More cmake fixes and a license typo fix.
[ne.git] / src / phys / generic_objects.cpp
blobe0cfe989c9cedc9ff622a1cfd0209f48983a4fd4
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;
34 dMassSetBox(&m_mass, density, x,y,z);
35 m_body->setMass(&m_mass);
36 init_geom();
37 shapes_init();
40 Box::~Box()
42 delete m_box;
45 void Box::draw()
47 glPushMatrix();
48 apply_matrix();
49 static dReal s[3];
50 m_box->getLengths(s);
51 glScalef(s[0],s[1],s[2]);
52 //draw_quad();
53 draw_cube();
54 //glColor3f(1,1,1);
55 //glutWireCube(1);
56 glPopMatrix();
59 /****************
60 * Sphere class *
61 ****************/
63 Sphere::Sphere(float r, float density)
65 m_sphere = new dSphere(World::Instance()->getSpace()->id(),r);
66 m_geom = m_sphere;
67 dMassSetSphere(&m_mass, density, r);
68 m_body->setMass(&m_mass);
69 init_geom();
72 Sphere::~Sphere()
74 delete m_sphere;
77 void Sphere::draw()
79 glPushMatrix();
80 apply_matrix();
81 static dReal s;
82 s = m_sphere->getRadius();
83 glScalef(s,s,s);
84 //draw_circle();
85 //glutWireSphere(1,64,64);
86 static GLUquadricObj *q = 0;
87 if (q == 0)
89 q = gluNewQuadric();
90 gluQuadricNormals(q, GL_SMOOTH);
91 gluQuadricTexture(q, GL_TRUE);
92 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
93 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
95 glRotatef(90,1,0,0);
96 gluSphere(q,1,32,32);
98 glEnable(GL_TEXTURE_GEN_S);
99 glEnable(GL_TEXTURE_GEN_T);
100 glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
101 glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
103 glPopMatrix();