ScummVM API documentation
PhysicsJointNewton.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 /*
23  * Copyright (C) 2006-2010 - Frictional Games
24  *
25  * This file is part of HPL1 Engine.
26  */
27 
28 #ifndef HPL_PHYSICS_JOINT_NEWTON_H
29 #define HPL_PHYSICS_JOINT_NEWTON_H
30 
31 #include "hpl1/engine/impl/PhysicsBodyNewton.h"
32 #include "hpl1/engine/impl/PhysicsWorldNewton.h"
33 #include "hpl1/engine/libraries/newton/Newton.h"
34 
35 #include "hpl1/engine/system/low_level_system.h"
36 
37 namespace hpl {
38 
39 template<typename T>
40 class iPhysicsJointNewton : public T {
41 public:
42  iPhysicsJointNewton(const tString &asName, iPhysicsBody *apParentBody, iPhysicsBody *apChildBody,
43  iPhysicsWorld *apWorld, const cVector3f &avPivotPoint)
44  : T(asName, apParentBody, apChildBody, apWorld, avPivotPoint) {
45  cPhysicsWorldNewton *pNWorld = static_cast<cPhysicsWorldNewton *>(apWorld);
46 
47  mpNewtonWorld = pNWorld->GetNewtonWorld();
48 
49  cPhysicsBodyNewton *pNParent = static_cast<cPhysicsBodyNewton *>(apParentBody);
50  cPhysicsBodyNewton *pNChild = static_cast<cPhysicsBodyNewton *>(apChildBody);
51 
52  if (apParentBody == NULL)
53  mpNewtonParentBody = NULL;
54  else
55  mpNewtonParentBody = pNParent->GetNewtonBody();
56 
57  mpNewtonChildBody = pNChild->GetNewtonBody();
58  }
59 
60  virtual ~iPhysicsJointNewton() {
61  // Skip this for now and let newton handle it..
62  // Log("Destroying newton joint!\n");
63  if (this->mpChildBody || this->mpParentBody)
64  NewtonDestroyJoint(mpNewtonWorld, mpNewtonJoint);
65  }
66 
68 
69  void SetCollideBodies(bool abX) {
70  NewtonJointSetCollisionState(mpNewtonJoint, abX ? 1 : 0);
71  }
72 
73  bool GetCollideBodies() {
74  return NewtonJointGetCollisionState(mpNewtonJoint) == 0 ? false : true;
75  }
76 
78 
79  void SetStiffness(float afX) {
80  NewtonJointSetStiffness(mpNewtonJoint, afX);
81  }
82  float GetStiffness() {
83  return NewtonJointGetStiffness(mpNewtonJoint);
84  }
85 
87 
88 protected:
89  NewtonJoint *mpNewtonJoint;
90  NewtonWorld *mpNewtonWorld;
91  NewtonBody *mpNewtonParentBody;
92  NewtonBody *mpNewtonChildBody;
93 };
94 
95 } // namespace hpl
96 
97 #endif // HPL_PHYSICS_JOINT_NEWTON_H
Definition: AI.h:36
Definition: str.h:59
Definition: PhysicsWorld.h:115
Definition: PhysicsJointNewton.h:40
Definition: PhysicsBody.h:117
Definition: PhysicsWorldNewton.h:36
Definition: PhysicsBodyNewton.h:41