1 #include <G3D/G3DAll.h>
2 #include <GLG3D/GLG3D.h>
7 EntityHandle
Entity::lastHandle
= 0x1;
9 G3D::Table
<EntityHandle
, Entity
*> Entity::entities
;
11 Entity::Entity(void) : selected(false)
13 handle
= Entity::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
));
45 ent
->at
.translation
= G3D::Vector3(ecl_to_float(x
),ecl_to_float(y
),ecl_to_float(z
));
51 cl_object
cl_get_entity_position(cl_object handle
)
53 Entity
*ent
= Entity::get(fix(handle
));
55 float x
= ent
->at
.translation
.x
;
56 float y
= ent
->at
.translation
.y
;
57 float z
= ent
->at
.translation
.z
;
60 VALUES(0) = ecl_make_singlefloat(x
);
61 VALUES(1) = ecl_make_singlefloat(y
);
62 VALUES(2) = ecl_make_singlefloat(z
);
69 cl_object
cl_get_entity_orientation(cl_object handle
)
71 Entity
*ent
= Entity::get(ecl_to_fixnum(handle
));
74 G3D::Quat
q(ent
->at
.rotation
);
77 q
.toAxisAngleRotation( axis
, angle
);
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
);
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
));
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
));
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
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
));
138 ent
->solidColor
= Color4( ecl_to_float(r
), ecl_to_float(g
), ecl_to_float(b
), ecl_to_float(a
) );
144 cl_object
cl_get_entity_solid_color(cl_object handle
)
146 Entity
*ent
= Entity::get(ecl_to_fixnum(handle
));
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
);
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
));
165 ent
->wireColor
= Color4( ecl_to_float(r
), ecl_to_float(g
), ecl_to_float(b
), ecl_to_float(a
) );
171 cl_object
cl_get_entity_wire_color(cl_object handle
)
173 Entity
*ent
= Entity::get(ecl_to_fixnum(handle
));
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
);
186 Entity::~Entity(void)
188 entities
.remove(handle
);