1 /*
2  * NodeRigidBody.h
3  *
4  * Copyright (C) 1999 Stephen F. White, 2007 J. "MUFTI" Scheurich
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program (see the file "COPYING" for details); if
18  * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19  * Cambridge, MA 02139, USA.
20  */
21 
22 #pragma once
23 
24 #include "RigidBodyPhysicsNode.h"
25 #include "SFMFTypes.h"
26 
27 class ProtoRigidBody : public Proto {
28 public:
29                   ProtoRigidBody(Scene *scene);
30     virtual Node *create(Scene *scene);
31 
getType()32     virtual int   getType() const { return X3D_RIGID_BODY; }
33 
isX3dInternalProto(void)34     virtual bool  isX3dInternalProto(void) { return true; }
35 
36     FieldIndex angularDampingFactor;
37     FieldIndex angularVelocity;
38     FieldIndex autoDamp;
39     FieldIndex autoDisable;
40     FieldIndex centerOfMass;
41     FieldIndex disableAngularSpeed;
42     FieldIndex disableLinearSpeed;
43     FieldIndex disableTime;
44     FieldIndex enabled;
45     FieldIndex finiteRotationAxis;
46     FieldIndex fixed;
47     FieldIndex forces;
48     FieldIndex geometry;
49     FieldIndex inertia;
50     FieldIndex linearDampingFactor;
51     FieldIndex linearVelocity;
52     FieldIndex mass;
53     FieldIndex massDensityModel;
54     FieldIndex orientation;
55     FieldIndex position;
56     FieldIndex torques;
57     FieldIndex useFiniteRotation;
58     FieldIndex useGlobalGravity;
59 };
60 
61 class NodeRigidBody : public RigidBodyPhysicsNode {
62 public:
63                     NodeRigidBody(Scene *scene, Proto *proto);
64 
getComponentName(void)65     virtual const char* getComponentName(void) const
66                            { return "RigidBodyPhysics"; }
getComponentLevel(void)67     virtual int         getComponentLevel(void) const { return 2; }
getX3dVersion(void)68     virtual int         getX3dVersion(void) const { return 2; }
copy()69     virtual Node       *copy() const { return new NodeRigidBody(*this); }
70 
71     virtual void       preDraw();
72     virtual void       draw(int pass);
73 
74     virtual void       setField(int index, FieldValue *value, int cf = -1);
75     virtual void       drawHandles(void);
76     virtual void       transform();
77     virtual void       transformForHandle(int handle);
78 
79     virtual Vec3f      getHandle(int handle, int *constraint, int *field);
80     virtual void       setHandle(int handle, const Vec3f &v);
81 
showFields()82     virtual bool       showFields() { return true; }
83 
84     void               drawVelocityHandles(float handleScale);
85 
update()86     virtual void       update() { geometry()->update(); }
87 
88     fieldMacros(SFFloat,    angularDampingFactor, ProtoRigidBody)
89     fieldMacros(SFVec3f,    angularVelocity,      ProtoRigidBody)
90     fieldMacros(SFBool,     autoDamp,             ProtoRigidBody)
91     fieldMacros(SFBool,     autoDisable,          ProtoRigidBody)
92     fieldMacros(SFVec3f,    centerOfMass,         ProtoRigidBody)
93     fieldMacros(SFFloat,    disableAngularSpeed,  ProtoRigidBody)
94     fieldMacros(SFFloat,    disableLinearSpeed,   ProtoRigidBody)
95     fieldMacros(SFFloat,    disableTime,          ProtoRigidBody)
96     fieldMacros(SFBool,     enabled,              ProtoRigidBody)
97     fieldMacros(SFVec3f,    finiteRotationAxis,   ProtoRigidBody)
98     fieldMacros(SFBool,     fixed,                ProtoRigidBody)
99     fieldMacros(MFVec3f,    forces,               ProtoRigidBody)
100     fieldMacros(MFNode,     geometry,             ProtoRigidBody)
101     fieldMacros(SFMatrix3f, inertia,              ProtoRigidBody)
102     fieldMacros(SFFloat,    linearDampingFactor,  ProtoRigidBody)
103     fieldMacros(SFVec3f,    linearVelocity,       ProtoRigidBody)
104     fieldMacros(SFFloat,    mass,                 ProtoRigidBody)
105     fieldMacros(SFNode,     massDensityModel,     ProtoRigidBody)
106     fieldMacros(SFRotation, orientation,          ProtoRigidBody)
107     fieldMacros(SFVec3f,    position,             ProtoRigidBody)
108     fieldMacros(MFVec3f,    torques,              ProtoRigidBody)
109     fieldMacros(SFBool,     useFiniteRotation,    ProtoRigidBody)
110     fieldMacros(SFBool,     useGlobalGravity,     ProtoRigidBody)
111 
112 private:
113     bool              m_matrixDirty;
114     Matrix            m_matrix;
115     float             m_handleScale;
116     int               m_handleNameLinearVelocity;
117     int               m_handleNameAngularVelocityX1;
118     int               m_handleNameAngularVelocityY1;
119     int               m_handleNameAngularVelocityZ1;
120     int               m_handleNameAngularVelocityX2;
121     int               m_handleNameAngularVelocityY2;
122     int               m_handleNameAngularVelocityZ2;
123 };
124 
125 
126