AnimatLab  2
Test
OsgMovableItem.h
1 
2 #pragma once
3 
4 #include "OsgGeometry.h"
5 
6 namespace OsgAnimatSim
7 {
8  class OsgSimulator;
9 
10  namespace Environment
11  {
12 
14  {
15  protected:
16  AnimatBase *m_lpThisAB;
17  MovableItem *m_lpThisMI;
18  OsgMovableItem *m_lpThisVsMI;
19  OsgMovableItem *m_lpParentVsMI;
20  OsgSimulator *m_lpOsgSim;
21 
22  osg::Matrix m_osgWorldMatrix;
23 
24  osg::ref_ptr<osg::MatrixTransform> m_osgParent;
25  osg::ref_ptr<osgManipulator::Selection> m_osgMT;
26  osg::ref_ptr<osg::Geometry> m_osgGeometry;
27  osg::ref_ptr<osg::Group> m_osgRoot;
28  osg::ref_ptr<osg::Node> m_osgNode;
29  osg::ref_ptr<osg::Group> m_osgNodeGroup;
30  osg::ref_ptr<osg::Node> m_osgDebugNode;
31 
32  osg::ref_ptr<osg::CullFace> m_osgCull;
33  osg::ref_ptr<osg::Texture2D> m_osgTexture;
34 
35  osg::ref_ptr<osg::StateSet> m_osgStateSet;
36  osg::ref_ptr<osg::Material> m_osgMaterial;
37 
38  osg::ref_ptr<osg::Group> m_osgSelectedGroup;
39  osg::ref_ptr<OsgDragger> m_osgDragger;
40 
41  osg::Matrix m_osgLocalMatrix;
42 
47  osg::ref_ptr< osg::MatrixTransform> m_osgGeometryRotationMT;
48 
49  //Some parts, like joints, have an additional offset matrix. This
50  //Final Matrix is the combination of the local and offset matrix.
51  osg::Matrix m_osgFinalMatrix;
52  bool m_bCullBackfaces;
53  osg::StateAttribute::GLMode m_eTextureMode;
54 
55  osg::ref_ptr<osg::MatrixTransform> m_osgSelVertexMT;
56  osg::ref_ptr<osg::Geode> m_osgSelVertexNode;
57 
58  virtual void SetThisPointers();
59  virtual void LocalMatrix(osg::Matrix osgLocalMT);
60  virtual void GeometryRotationMatrix(osg::Matrix osgGeometryMT);
61 
62  virtual void CreateSelectedGraphics(std::string strName);
63  virtual void CreateDragger(std::string strName);
64  virtual void CreateSelectedVertex(std::string strName);
65  virtual void DeleteSelectedVertex();
66  virtual void AttachedPartMovedOrRotated(std::string strID);
67  virtual void UpdatePositionAndRotationFromMatrix();
68  virtual void UpdatePositionAndRotationFromMatrix(osg::Matrix osgMT);
69  virtual osg::Matrix CalculateTransformRelativeToParent(osg::Matrix osgLocalMatrix);
70 
71  virtual void InitializeGraphicsGeometry();
72  virtual void CreateGraphicsGeometry();
73  virtual void CreatePhysicsGeometry();
74  virtual void CreateGeometry(bool bOverrideStatic = false);
75  virtual void ResizePhysicsGeometry();
76  virtual void ResetPhyiscsAndChildJoints();
77 
78  virtual void UpdateWorldMatrix();
79 
80  virtual void ShowSelectedVertex();
81  virtual void HideSelectedVertex();
82 
83  public:
85  virtual ~OsgMovableItem();
86 
87  virtual OsgSimulator *GetOsgSimulator();
88  virtual OsgMovableItem *VsParent();
89  virtual osg::MatrixTransform *ParentOSG() = 0;
90  virtual osg::Group *RootGroup() {return m_osgRoot.get();};
91  virtual osg::Group *NodeGroup() {return m_osgNodeGroup.get();};
92  virtual osg::Matrix LocalMatrix() {return m_osgLocalMatrix;};
93  virtual osg::Matrix FinalMatrix() {return m_osgFinalMatrix;};
94  virtual void FinalMatrix(osg::Matrix vFinal);
95 
96  virtual void Physics_SetParent(MovableItem *lpParent)
97  {
98  m_lpParentVsMI = dynamic_cast<OsgMovableItem *>(lpParent);
99  };
100  virtual void Physics_SetChild(MovableItem *lpParent) {};
101 
102 
103  //virtual CStdFPoint GetOSGWorldCoords(osg::MatrixTransform *osgMT);
104  virtual CStdFPoint GetOSGWorldCoords();
105  virtual osg::Matrix GetOSGWorldMatrix(bool bUpdate = false);
106  //virtual osg::Matrix GetOSGWorldMatrix(osg::MatrixTransform *osgMT);
107 
108  virtual void SetupGraphics();
109  virtual void SetupPhysics() = 0;
110  virtual void DeleteGraphics();
111  virtual void DeletePhysics(bool bIncludeChildren) = 0;
112 
113  virtual void StartGripDrag();
114  virtual void EndGripDrag();
115 
116  virtual std::string Physics_ID();
117  virtual void Physics_UpdateMatrix();
118  virtual void Physics_ResetGraphicsAndPhysics();
119  virtual void Physics_PositionChanged();
120  virtual void Physics_RotationChanged();
121  virtual void Physics_UpdateAbsolutePosition();
122  virtual void Physics_Selected(bool bValue, bool bSelectMultiple);
123  virtual float Physics_GetBoundingRadius();
124  virtual BoundingBox Physics_GetBoundingBox();
125  virtual void Physics_SetColor() {};
126  virtual void Physics_TextureChanged() {};
127  virtual void Physics_CollectData();
128  virtual void Physics_CollectExtraData() {};
129  virtual void Physics_ResetSimulation();
130  virtual void Physics_AfterResetSimulation() {};
131  virtual float *Physics_GetDataPointer(const std::string &strDataType);
132  virtual void Physics_OrientNewPart(float fltXPos, float fltYPos, float fltZPos, float fltXNorm, float fltYNorm, float fltZNorm);
133  virtual void Physics_SelectedVertex(float fltXPos, float fltYPos, float fltZPos) {};
134  virtual bool Physics_CalculateLocalPosForWorldPos(float fltWorldX, float fltWorldY, float fltWorldZ, CStdFPoint &vLocalPos);
135  virtual void Physics_LoadLocalTransformMatrix(CStdXml &oXml);
136  virtual void Physics_SaveLocalTransformMatrix(CStdXml &oXml);
137  virtual std::string Physics_GetLocalTransformMatrixString();
138  virtual void Physics_ResizeDragHandler(float fltRadius);
139 
140  virtual void SetTexture(std::string strTexture);
141  virtual void SetCulling();
142  virtual void SetColor(CStdColor &vAmbient, CStdColor &vDiffuse, CStdColor &vSpecular, float fltShininess);
143  virtual void SetAlpha();
144  virtual void SetMaterialAlpha(osg::Material *osgMat, osg::StateSet *ss, float fltAlpha);
145  virtual void SetVisible(bool bVisible);
146  virtual void SetVisible(osg::Node *osgNode, bool bVisible);
147 
148  virtual void CreateItem();
149  virtual bool AddOsgNodeToParent() {return true;};
150 
151  virtual osg::Matrix GetWorldMatrix();
152  virtual osg::Matrix GetPhysicsWorldMatrix() {return GetWorldMatrix();};
153  virtual osg::Matrix GetComMatrix(bool bInvert = false);
154 
155  virtual osg::Matrix GetParentWorldMatrix();
156  virtual osg::Matrix GetParentPhysicsWorldMatrix();
157  virtual osg::Matrix GetParentComMatrix(bool bInvert = false);
158 
159  virtual osg::MatrixTransform* GetMatrixTransform();
160  virtual osg::MatrixTransform* GetCameraMatrixTransform();
161 
162  virtual void BuildLocalMatrix();
163  virtual void BuildLocalMatrix(CStdFPoint vLocalOffset);
164  virtual void BuildLocalMatrix(CStdFPoint localPos, CStdFPoint vLocalOffset, CStdFPoint localRot, std::string strName);
165  };
166 
167  } // Environment
168 } //OsgAnimatSim
169 
170 
osg::ref_ptr< osg::MatrixTransform > m_osgGeometryRotationMT
Classes for implementing the cm-labs vortex physics engine for AnimatLab.