Point entity works. Default colours are sensible.
[Procustean.git] / src / Entity.h
blob726f0e81593e43056132fa77338cc0bf4fbdecf6
2 #ifndef ENTITY_H_INCLUDED
3 #define ENTITY_H_INCLUDED
5 namespace G3D
8 // these two virtual functions are unimplemented in G3D-7.00 because of a typo.
9 class TurtleAxesShape : public AxesShape
11 public:
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.");
24 static AABox aab;
25 return aab;
29 // these two virtual functions are unimplemented in G3D-7.00 because of a typo.
30 class TurtleRayShape : public RayShape
32 public:
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.");
45 static AABox aab;
46 return aab;
50 class TriangleShape : public Shape
52 G3D::Triangle geometry;
54 public:
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
63 return 0.0f;
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
84 G3D::AABox result;
85 geometry.getBounds(result);
86 return result;
90 void getRandomSurfacePoint(Vector3& P, Vector3& N = Vector3::dummy) const
92 P = geometry.randomPoint();
93 N = geometry.normal();
94 return;
97 Vector3 randomInteriorPoint() const
99 return geometry.randomPoint();
102 void render(RenderDevice* rd,
103 const CoordinateFrame& cframe,
104 Color4 solidColor,
105 Color4 wireColor)
107 CoordinateFrame cframe0 = rd->getObjectToWorldMatrix();
109 rd->pushState();
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);
119 rd->sendVertex(v0);
120 rd->sendVertex(v1);
121 rd->sendVertex(v2);
122 rd->endPrimitive();
124 rd->setBlendFunc(RenderDevice::BLEND_SRC_ALPHA, RenderDevice::BLEND_ONE_MINUS_SRC_ALPHA);
125 rd->setLineWidth(2);
126 rd->setColor(wireColor);
127 rd->beginPrimitive(RenderDevice::LINES);
128 rd->sendVertex(v0);
129 rd->sendVertex(v1);
130 rd->sendVertex(v1);
131 rd->sendVertex(v2);
132 rd->sendVertex(v2);
133 rd->sendVertex(v0);
134 rd->endPrimitive();
135 rd->popState();
139 } // end namespece G3D
147 typedef cl_fixnum EntityHandle;
150 class Entity
152 protected:
153 Entity();
154 ~Entity();
155 static EntityHandle lastHandle;
156 static G3D::Table<EntityHandle, Entity* > entities;
158 public:
159 G3D::CoordinateFrame at;
160 G3D::Color4 solidColor;
161 G3D::Color4 wireColor;
162 G3D::ShapeRef myShape;
163 EntityHandle handle;
164 bool selected;
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?)
228 #endif