From 3617b6ad8c1ec4820ec599b5466c28cdc11617ba Mon Sep 17 00:00:00 2001 From: frohlich Date: Thu, 4 Jan 2007 12:52:50 +0000 Subject: [PATCH] Modified Files: Makefile.am SGNodeMasks.hxx Added Files: SGPickCallback.hxx SGSceneUserData.hxx: Preparations for generic scenery picking. --- simgear/scene/util/Makefile.am | 2 + simgear/scene/util/SGNodeMasks.hxx | 8 ++-- simgear/scene/util/SGPickCallback.hxx | 51 ++++++++++++++++++++++ simgear/scene/util/SGSceneUserData.hxx | 59 ++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 simgear/scene/util/SGPickCallback.hxx create mode 100644 simgear/scene/util/SGSceneUserData.hxx diff --git a/simgear/scene/util/Makefile.am b/simgear/scene/util/Makefile.am index 0d863524..cc3edccc 100644 --- a/simgear/scene/util/Makefile.am +++ b/simgear/scene/util/Makefile.am @@ -8,6 +8,8 @@ include_HEADERS = \ SGNodeMasks.hxx \ SGUpdateVisitor.hxx \ SGDebugDrawCallback.hxx \ + SGPickCallback.hxx \ + SGSceneUserData.hxx \ SGStateAttributeVisitor.hxx \ SGTextureStateAttributeVisitor.hxx diff --git a/simgear/scene/util/SGNodeMasks.hxx b/simgear/scene/util/SGNodeMasks.hxx index 315d73fc..07d5a0ed 100644 --- a/simgear/scene/util/SGNodeMasks.hxx +++ b/simgear/scene/util/SGNodeMasks.hxx @@ -1,6 +1,6 @@ /* -*-c++-*- * - * Copyright (C) 2006 Mathias Froehlich + * Copyright (C) 2006-2007 Mathias Froehlich * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -23,10 +23,10 @@ #define SG_SCENE_NODEMASKS_HXX /// If set, do terrain elevation computations with that nodes -#define SG_NODEMASK_TERRAIN_BIT (1<<0) +#define SG_NODEMASK_TERRAIN_BIT (1<<0) /// If set, cast shadows -#define SG_NODEMASK_SHADOW_BIT (1<<1) +#define SG_NODEMASK_SHADOW_BIT (1<<1) /// If set, the node is pickable -#define SG_NODEMASK_PICK_BIT (1<<2) +#define SG_NODEMASK_PICK_BIT (1<<2) #endif diff --git a/simgear/scene/util/SGPickCallback.hxx b/simgear/scene/util/SGPickCallback.hxx new file mode 100644 index 00000000..baaef436 --- /dev/null +++ b/simgear/scene/util/SGPickCallback.hxx @@ -0,0 +1,51 @@ +/* -*-c++-*- + * + * Copyright (C) 2006-2007 Mathias Froehlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + */ + +#ifndef SG_SCENE_PICKCALLBACK_HXX +#define SG_SCENE_PICKCALLBACK_HXX + +#include +#include + +// Used to implement scenery interaction. +// The interface is still under development +class SGPickCallback : public SGReferenced { +public: + struct Info { + SGVec3d wgs84; + SGVec3d local; + }; + + virtual ~SGPickCallback() {} + virtual bool buttonPressed(int button, const Info& info) + { return false; } + virtual void update(double dt) + { } + virtual void buttonReleased(void) + { } +}; + +struct SGSceneryPick { + SGPickCallback::Info info; + SGSharedPtr callback; +}; + +#endif diff --git a/simgear/scene/util/SGSceneUserData.hxx b/simgear/scene/util/SGSceneUserData.hxx new file mode 100644 index 00000000..e8acbe9e --- /dev/null +++ b/simgear/scene/util/SGSceneUserData.hxx @@ -0,0 +1,59 @@ +/* -*-c++-*- + * + * Copyright (C) 2006-2007 Mathias Froehlich + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + */ + +#ifndef SG_SCENE_USERDATA_HXX +#define SG_SCENE_USERDATA_HXX + +#include +#include +#include "SGPickCallback.hxx" + +class SGSceneUserData : public osg::Referenced { +public: + static SGSceneUserData* getSceneUserData(osg::Node* node) + { + if (!node) + return 0; + osg::Referenced* referenced = node->getUserData(); + if (!referenced) + return 0; + return dynamic_cast(referenced); + } + static SGSceneUserData* getOrCreateSceneUserData(osg::Node* node) + { + SGSceneUserData* userData = getSceneUserData(node); + if (userData) + return userData; + userData = new SGSceneUserData; + node->setUserData(userData); + return userData; + } + + SGPickCallback* getPickCallback() const + { return _pickCallback; } + void setPickCallback(SGPickCallback* pickCallback) + { _pickCallback = pickCallback; } + +private: + SGSharedPtr _pickCallback; +}; + +#endif -- 2.39.5