1 /***************************************************************************
2 * Copyright (C) 2008 by Scott West *
3 * westsg2@mcmaster.ca *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
26 Box::Box (Vector pos
, Vector size
) :
30 // FIXME: default mass, add mass option to the constructor later
32 // initially no inertia
33 btVector3
inertia (0,0,0);
35 // the box shape and size
36 btBoxShape
* btBox
= new btBoxShape (btVector3 (sz
.x
/2,
41 // this represents the box position and orientation
42 btTransform boxInitTrans
;
43 boxInitTrans
.setIdentity ();
44 boxInitTrans
.setOrigin (btVector3 (p
.x
, p
.y
, p
.z
));
46 btDefaultMotionState
* btBoxState
=
47 new btDefaultMotionState (boxInitTrans
);
49 // set the shape's moving properties, inertia, mass.
50 btBox
->calculateLocalInertia (mass
, inertia
);
52 // create a rigid body with the mass, shape, inertia.
53 btRigidBody::btRigidBodyConstructionInfo boxCI
54 (mass
, btBoxState
, btBox
, inertia
);
56 btBoxBody
= new btRigidBody (boxCI
);
57 btBoxBody
->setSleepingThresholds(btScalar (0.1), btScalar (0.1));
65 void Box::update(const Box
& b
, double dt
)
70 Vector
Box::position (){
78 glNormal3f (0.0f
, 0.0f
, 1.0f
);
80 glVertex3f (-0.5, 0.5, 0.5);
81 glVertex3f ( 0.5, 0.5, 0.5);
82 glVertex3f ( 0.5, -0.5, 0.5);
83 glVertex3f (-0.5, -0.5, 0.5);
88 btRigidBody
* Box::getBody ()
97 for(int i
= 0; i
< 4; i
++)
99 glRotated (90.0, 0.0, 1.0, 0.0);
103 glRotated (90.0, 1.0, 0.0, 0.0);
106 glRotated (180.0, 1.0, 0.0, 0.0);
116 glColorMaterial (GL_FRONT_AND_BACK
, GL_AMBIENT_AND_DIFFUSE
);
117 glEnable (GL_COLOR_MATERIAL
);
119 glColor3f (1.0f
, 0.0f
, 0.0f
);
124 btBoxBody
->getMotionState ()->getWorldTransform (trans
);
125 trans
.getOpenGLMatrix (matrix
);
126 glMultMatrixf (matrix
);
128 glScaled (sz
.x
, sz
.y
, sz
.z
);
131 glColor3f (1.0f
, 1.0f
, 1.0f
);