Fixed some transforms, move to 3d and quaternion math in progress...
[ne.git] / src / phys / generic_objects.cpp
blob8cd8cfdb0cf840ea33937d7e521ff717385bbb19
1 /************************************************************************
2 This file is part of NE.
4 NE is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 NE is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with NE. If not, see <http://www.gnu.org/licenses/>.
16 ************************************************************************/
18 #include "generic_objects.h"
20 #include "backend/shapes.h"
21 #include "world.h"
22 #include <GL/gl.h>
23 #include <GL/glu.h>
24 #include <ode/ode.h>
26 /*************
27 * Box class *
28 *************/
30 Box::Box(float x, float y, float z, float density)
32 m_box = new dBox(World::Instance()->getSpace()->id(),x,y,z);
33 m_geom = m_box;
35 m_mass.setBox(density, x, y, z);
36 m_body->setMass(&m_mass);
38 shapes_init();
39 init_geom();
42 Box::~Box()
44 delete m_box;
47 void Box::draw()
49 glPushMatrix();
50 apply_matrix();
51 static dReal s[3];
52 m_box->getLengths(s);
53 glScalef(s[0],s[1],s[2]);
54 //draw_quad();
55 draw_cube();
56 //glColor3f(1,1,1);
57 //glutWireCube(1);
58 glPopMatrix();
61 /****************
62 * Sphere class *
63 ****************/
65 Sphere::Sphere(float r, float density)
67 m_sphere = new dSphere(World::Instance()->getSpace()->id(),r);
68 m_geom = m_sphere;
70 m_mass.setSphere(density, r);
71 m_body->setMass(&m_mass);
73 init_geom();
76 Sphere::~Sphere()
78 delete m_sphere;
81 void Sphere::draw()
83 glPushMatrix();
84 apply_matrix();
85 static dReal s;
86 s = m_sphere->getRadius();
87 glScalef(s,s,s);
88 //draw_circle();
89 //glutWireSphere(1,64,64);
90 static GLUquadricObj *q = 0;
91 if (q == 0)
93 q = gluNewQuadric();
94 gluQuadricNormals(q, GL_SMOOTH);
95 gluQuadricTexture(q, GL_TRUE);
96 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
97 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
99 glRotatef(-90,1,0,0);
100 gluSphere(q,1,32,32);
102 glEnable(GL_TEXTURE_GEN_S);
103 glEnable(GL_TEXTURE_GEN_T);
104 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
105 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
107 glPopMatrix();