Merge git+ssh://ares@repo.or.cz/srv/git/Procustean
[Procustean.git] / src / Entity.cpp
blob80b2f95a810c5bb1e3ab7da25633f129dbfcea4f
1 #include <G3D/G3DAll.h>
2 #include <GLG3D/GLG3D.h>
3 #include "TextShape.h"
4 #include "ecl/ecl.h"
5 #include "Entity.h"
7 EntityHandle Entity::lastHandle = 0x1;
9 G3D::Table<EntityHandle, Entity*> Entity::entities;
11 Entity::Entity(void) : selected(false)
13 handle = Entity::lastHandle;
14 lastHandle++;
15 entities.set(handle, this);
18 EntityHandle Entity::create()
20 Entity *result = new Entity();
21 return result->handle;
24 Entity *Entity::get(EntityHandle h)
26 return Entity::entities[h];
29 void Entity::renderEntities(G3D::RenderDevice* rd)
31 G3D::Table<EntityHandle, Entity*>::Iterator it = Entity::entities.begin();
32 for( ; it != Entity::entities.end(); ++it )
33 it->value->render(rd);
36 void Entity::updateEntities(float dt)
41 cl_object cl_set_entity_position(cl_object handle, cl_object x, cl_object y, cl_object z)
43 Entity *ent = Entity::get(fix(handle));
44 if (ent != NULL) {
45 ent->at.translation = G3D::Vector3(ecl_to_float(x),ecl_to_float(y),ecl_to_float(z));
46 return Ct;
48 return Cnil;
51 cl_object cl_get_entity_position(cl_object handle)
53 Entity *ent = Entity::get(fix(handle));
54 if (ent != NULL) {
55 float x = ent->at.translation.x;
56 float y = ent->at.translation.y;
57 float z = ent->at.translation.z;
59 NVALUES=3;
60 VALUES(0) = ecl_make_singlefloat(x);
61 VALUES(1) = ecl_make_singlefloat(y);
62 VALUES(2) = ecl_make_singlefloat(z);
63 return (VALUES(0));
65 return Cnil;
69 cl_object cl_get_entity_orientation(cl_object handle)
71 Entity *ent = Entity::get(ecl_to_fixnum(handle));
72 if (ent != NULL)
74 G3D::Quat q(ent->at.rotation);
75 G3D::Vector3 axis;
76 float angle;
77 q.toAxisAngleRotation( axis, angle );
79 NVALUES=4;
80 VALUES(0) = ecl_make_singlefloat(axis.x);
81 VALUES(1) = ecl_make_singlefloat(axis.y);
82 VALUES(2) = ecl_make_singlefloat(axis.z);
83 VALUES(3) = ecl_make_singlefloat(angle);
84 return VALUES(0);
86 return Cnil;
89 cl_object cl_set_entity_orientation(cl_object handle, cl_object x, cl_object y, cl_object z, cl_object a)
91 Entity *ent = Entity::get(fix(handle));
92 if (ent != NULL)
94 Vector3 axis( ecl_to_float(x), ecl_to_float(y), ecl_to_float(z) );
95 float angle = ecl_to_float(a);
96 ent->at.rotation = Matrix3(G3D::Quat::fromAxisAngleRotation( axis, angle ));
97 return Ct;
99 return Cnil;
102 cl_object cl_make_sphere_entity(cl_object radius)
104 EntityHandle handle = Entity::create();
105 Entity *ent = Entity::get(handle);
106 ent->myShape = new G3D::SphereShape( ecl_to_float(radius) );
107 return MAKE_FIXNUM(handle);
110 cl_object cl_make_axes_entity()
112 EntityHandle handle = Entity::create();
113 Entity *ent = Entity::get(handle);
114 G3D::CoordinateFrame frame;
115 ent->myShape = new G3D::TurtleAxesShape( frame );
116 return MAKE_FIXNUM(handle);
119 cl_object cl_make_box_entity(cl_object x, cl_object y, cl_object z)
121 EntityHandle handle = Entity::create();
122 Entity *ent = Entity::get(handle);
123 ent->myShape = new G3D::BoxShape( ecl_to_float(x), ecl_to_float(y), ecl_to_float(z) );
124 return MAKE_FIXNUM(handle);
127 cl_object cl_make_mesh_entity(cl_object vertices, cl_object indices)
129 // NYI -- needs thought
130 return Cnil;
133 cl_object cl_set_entity_solid_color(cl_object handle, cl_object r, cl_object g, cl_object b, cl_object a)
135 Entity *ent = Entity::get(fix(handle));
136 if (ent != NULL)
138 ent->solidColor = Color4( ecl_to_float(r), ecl_to_float(g), ecl_to_float(b), ecl_to_float(a) );
139 return Ct;
141 return Cnil;
144 cl_object cl_get_entity_solid_color(cl_object handle)
146 Entity *ent = Entity::get(ecl_to_fixnum(handle));
147 if (ent != NULL)
149 NVALUES=4;
150 VALUES(0) = ecl_make_singlefloat(ent->solidColor.r);
151 VALUES(1) = ecl_make_singlefloat(ent->solidColor.g);
152 VALUES(2) = ecl_make_singlefloat(ent->solidColor.b);
153 VALUES(3) = ecl_make_singlefloat(ent->solidColor.a);
154 return VALUES(0);
156 return Cnil;
160 cl_object cl_set_entity_wire_color(cl_object handle, cl_object r, cl_object g, cl_object b, cl_object a)
162 Entity *ent = Entity::get(fix(handle));
163 if (ent != NULL)
165 ent->wireColor = Color4( ecl_to_float(r), ecl_to_float(g), ecl_to_float(b), ecl_to_float(a) );
166 return Ct;
168 return Cnil;
171 cl_object cl_get_entity_wire_color(cl_object handle)
173 Entity *ent = Entity::get(ecl_to_fixnum(handle));
174 if (ent != NULL)
176 NVALUES=4;
177 VALUES(0) = ecl_make_singlefloat(ent->wireColor.r);
178 VALUES(1) = ecl_make_singlefloat(ent->wireColor.g);
179 VALUES(2) = ecl_make_singlefloat(ent->wireColor.b);
180 VALUES(3) = ecl_make_singlefloat(ent->wireColor.a);
181 return VALUES(0);
183 return Cnil;
186 Entity::~Entity(void)
188 entities.remove(handle);