2 #ifndef ENTITY_H_INCLUDED
3 #define ENTITY_H_INCLUDED
8 // these two virtual functions are unimplemented in G3D-7.00 because of a typo.
9 class TurtleAxesShape
: public AxesShape
12 TurtleAxesShape(const G3D::CoordinateFrame
&a
) : AxesShape(a
)
16 virtual G3D::Sphere
boundingSphere() const
18 return Sphere(center(), 1);
21 virtual G3D::AABox
boundingAABox() const
23 debugAssertM(false, "No bounding axis aligned box for axes.");
29 // these two virtual functions are unimplemented in G3D-7.00 because of a typo.
30 class TurtleRayShape
: public RayShape
33 TurtleRayShape(const G3D::Ray
&r
) : RayShape(r
)
37 virtual G3D::Sphere
boundingSphere() const
39 return Sphere(center(), 1);
42 virtual G3D::AABox
boundingAABox() const
44 debugAssertM(false, "No bounding axis aligned box for axes.");
50 class TriangleShape
: public Shape
52 G3D::Triangle geometry
;
55 TriangleShape(const G3D::Vector3
& v0
, const G3D::Vector3
& v1
, const G3D::Vector3
& v2
) : geometry(v0
, v1
, v2
)
59 virtual Type
type() const { return PLANE
; };
61 virtual float volume() const
66 Vector3
center() const
68 return geometry
.center();
72 virtual float area() const
74 return geometry
.area();
77 virtual G3D::Sphere
boundingSphere() const
79 return Sphere(center(), 1);
82 virtual G3D::AABox
boundingAABox() const
85 geometry
.getBounds(result
);
90 void getRandomSurfacePoint(Vector3
& P
, Vector3
& N
= Vector3::dummy
) const
92 P
= geometry
.randomPoint();
93 N
= geometry
.normal();
97 Vector3
randomInteriorPoint() const
99 return geometry
.randomPoint();
102 void render(RenderDevice
* rd
,
103 const CoordinateFrame
& cframe
,
107 CoordinateFrame cframe0
= rd
->getObjectToWorldMatrix();
110 rd
->setObjectToWorldMatrix(cframe0
* cframe
);
111 if (solidColor
.a
< 1.0) {
112 rd
->setBlendFunc(RenderDevice::BLEND_SRC_ALPHA
, RenderDevice::BLEND_ONE_MINUS_SRC_ALPHA
);
114 rd
->setColor(solidColor
);
115 rd
->beginPrimitive(RenderDevice::TRIANGLES
);
116 const Vector3 v0
= geometry
.vertex(0);
117 const Vector3 v1
= geometry
.vertex(1);
118 const Vector3 v2
= geometry
.vertex(2);
124 rd
->setBlendFunc(RenderDevice::BLEND_SRC_ALPHA
, RenderDevice::BLEND_ONE_MINUS_SRC_ALPHA
);
126 rd
->setColor(wireColor
);
127 rd
->beginPrimitive(RenderDevice::LINES
);
139 } // end namespece G3D
147 typedef cl_fixnum EntityHandle
;
155 static EntityHandle lastHandle
;
156 static G3D::Table
<EntityHandle
, Entity
* > entities
;
159 G3D::CoordinateFrame at
;
160 G3D::Color4 solidColor
;
161 G3D::Color4 wireColor
;
162 G3D::ShapeRef myShape
;
166 static EntityHandle
create();
167 static Entity
* get(EntityHandle h
);
169 void render(G3D::RenderDevice
* rd
)
171 myShape
->render(rd
, at
, solidColor
, wireColor
);
174 void update(float dt
);
176 static void renderEntities(G3D::RenderDevice
*);
177 static void updateEntities(float dt
);
182 void Render(EntityHandle handle
, G3D::RenderDevice
*rd
);
183 void Update(EntityHandle handle
, float dt
);
185 //void EntityHandle updateHook(..); hook update to lisp function
186 //void EndityHandle renderHook(..); hook render to lisp function
188 extern cl_object
cl_make_sphere_entity(cl_object radius
);
189 extern cl_object
cl_make_axes_entity(void);
190 extern cl_object
cl_make_box_entity(cl_object x
, cl_object y
, cl_object z
);
191 extern cl_object
cl_make_triangle_entity(cl_object x0
, cl_object y0
, cl_object z0
,
192 cl_object x1
, cl_object y1
, cl_object z1
,
193 cl_object x2
, cl_object y2
, cl_object z2
);
194 extern cl_object
cl_make_point_entity(cl_object x
, cl_object y
, cl_object z
);
196 extern cl_object
cl_make_mesh_entity(cl_object vertices
, cl_object indices
);
198 extern cl_object
cl_set_entity_position(cl_object handle
, cl_object x
, cl_object y
, cl_object z
);
199 extern cl_object
cl_get_entity_position(cl_object handle
);
201 extern cl_object
cl_set_entity_orientation(cl_object handle
, cl_object x
, cl_object y
, cl_object z
, cl_object angle
);
202 extern cl_object
cl_get_entity_orientation(cl_object handle
);
204 extern cl_object
cl_set_entity_solid_color(cl_object handle
, cl_object r
, cl_object g
, cl_object b
, cl_object a
);
205 extern cl_object
cl_get_entity_solid_color(cl_object handle
);
207 extern cl_object
cl_set_entity_wire_color(cl_object handle
, cl_object r
, cl_object g
, cl_object b
, cl_object a
);
208 extern cl_object
cl_get_entity_wire_color(cl_object handle
);
210 extern cl_object
cl_entity_yaw(cl_object handle
, cl_object value
);
211 extern cl_object
cl_entity_pitch(cl_object handle
, cl_object value
);
212 extern cl_object
cl_entity_roll(cl_object handle
, cl_object value
);
213 extern cl_object
cl_entity_forward(cl_object handle
, cl_object value
);
214 extern cl_object
cl_entity_backward(cl_object handle
, cl_object value
);
215 extern cl_object
cl_entity_up(cl_object handle
, cl_object value
);
216 extern cl_object
cl_entity_down(cl_object handle
, cl_object value
);
217 extern cl_object
cl_entity_left(cl_object handle
, cl_object value
);
218 extern cl_object
cl_entity_right(cl_object handle
, cl_object value
);
219 extern cl_object
cl_entity_mark_point(cl_object handle
);
220 extern cl_object
cl_entity_mark_line(cl_object handle
);
221 extern cl_object
cl_entity_mark_triangle(cl_object handle
);
222 extern cl_object
cl_object_mark_colour(cl_object handle
, cl_object r
, cl_object g
, cl_object b
, cl_object a
);
224 // extern cl_object cl_entity_scale(cl_object handle, cl_object x, cl_object y, cl_object z)
225 // extern cl_object cl_import_mesh_entity(cl_object handle, cl_object name)
226 // extern cl_object cl_clone_child_entity(cl_object handle); // create a child entity of the same type as the parent, (uses relative coordspace?)