Updated the to use static libraries too.
[blobbuild.git] / box.cpp
blobc6fe0d26b128ef9d2fccc070ec7df76d92798e13
1 /***************************************************************************
2 * Copyright (C) 2008 by Scott West *
3 * westsg2@mcmaster.ca *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20 #include "box.h"
22 #include <iostream>
23 #include <math.h>
26 Box::Box (Vector pos, Vector size) :
27 p (pos),
28 sz (size)
30 // FIXME: default mass, add mass option to the constructor later
31 btScalar mass = 1;
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,
37 sz.y/2,
38 sz.z/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));
61 Box::~Box ()
65 void Box::update(const Box& b, double dt)
70 Vector Box::position (){
71 return p;
74 void Box::drawQuad ()
76 glBegin (GL_QUADS);
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);
85 glEnd ();
88 btRigidBody* Box::getBody ()
90 return btBoxBody;
93 void Box::drawBox ()
95 glPushMatrix ();
97 for(int i = 0; i < 4; i++)
99 glRotated (90.0, 0.0, 1.0, 0.0);
100 drawQuad ();
103 glRotated (90.0, 1.0, 0.0, 0.0);
104 drawQuad ();
106 glRotated (180.0, 1.0, 0.0, 0.0);
107 drawQuad ();
109 glPopMatrix ();
112 void Box::render ()
114 glPushMatrix ();
116 glColorMaterial (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
117 glEnable (GL_COLOR_MATERIAL);
119 glColor3f (1.0f, 0.0f, 0.0f);
121 btTransform trans;
122 btScalar matrix[16];
124 btBoxBody->getMotionState ()->getWorldTransform (trans);
125 trans.getOpenGLMatrix (matrix);
126 glMultMatrixf (matrix);
128 glScaled (sz.x, sz.y, sz.z);
129 drawBox ();
131 glColor3f (1.0f, 1.0f, 1.0f);
133 glPopMatrix ();