Go to the documentation of this file.
5 #ifndef GLVERTEX_OBJECT_H
6 #define GLVERTEX_OBJECT_H
27 partial_trnsp_(false),
38 virtual void initObject() {}
39 virtual void renderObject() = 0;
40 virtual void preupdateObject(
double dt) {}
41 virtual void updateObject(
double dt) {}
53 transparency_ = color_.a < 1;
59 return(transparency_);
71 return(partial_trnsp_);
77 partial_trnsp_ = flag;
83 return(transformation_);
115 if (scale_.y > s) s = scale_.y;
116 if (scale_.z > s) s = scale_.z;
123 return(scale_.x==scale_.y && scale_.y==scale_.z);
160 transformation_ *=
mat3(q);
224 mat4 transformation_;
245 double l = d.
length()-radius;
253 if (d.x < 0) d.x = -d.x;
254 if (d.y < 0) d.y = -d.y;
255 if (d.z < 0) d.z = -d.z;
257 if (d.x<0 && d.y<0 && d.z<0)
260 if (d.y > l) l = d.y;
261 if (d.z > l) l = d.z;
266 if (d.x < 0) d.x = 0;
267 if (d.y < 0) d.y = 0;
268 if (d.z < 0) d.z = 0;
351 virtual void renderObject()
444 virtual void renderObject()
450 virtual void preupdateObject(
double dt)
456 virtual void updateObject(
double dt)
523 class lgl_DepthSortCompare
527 lgl_DepthSortCompare(
vec3 eye)
548 typedef std::vector<lgl_Object*>::iterator iterator;
563 for (iterator it=begin(); it!=end(); it++)
568 (*it)->renderTransformedObject();
574 void depthSort(
vec3 eye)
576 lgl_DepthSortCompare customLess(eye);
577 std::sort(begin(), end(), customLess);
588 typedef std::list<lgl_Object*>::iterator iterator;
598 for (iterator it=
begin(); it!=
end(); it++)
612 for (iterator it=
begin(); it!=
end(); it++)
622 iterator result =
end();
623 double distance = radius;
625 for (iterator it=
begin(); it!=
end(); it++)
627 double d = (*it)->getDistanceToObject(center);
665 return(std::list<lgl_Object*>::begin());
671 return(std::list<lgl_Object*>::end());
693 for (iterator it=
begin(); it!=
end(); it++)
698 (*it)->renderTransformedObject();
709 for (iterator it=
begin(); it!=
end(); it++)
714 if (!((*it)->hasTransparency()))
715 (*it)->renderTransformedObject();
717 if (!((*it)->hasPartialTransparency()))
720 partial_objs.push_back(*it);
734 for (iterator it=
begin(); it!=
end(); it++)
739 (*it)->preupdateObject(dt);
746 for (iterator it=
begin(); it!=
end(); it++)
751 (*it)->updateObject(dt);
769 mass_(0), restitution_(1),
818 return(restitution_);
824 restitution_ = restitution;
827 void setTransformation(
const mat4 &m)
832 transformationChanged(transformation_);
835 virtual mat4 getPhysicalTransformation() = 0;
837 void setPhysicalTransformation(
const mat4 &m)
842 void move(
const vec3 &delta)
847 transformationChanged(transformation_);
850 void rotate(
const quat &q)
855 transformationChanged(transformation_);
858 void scale(
double factor)
864 void scale(
vec3 factor)
873 velocity_ = velocity;
876 velocityChanged(velocity_);
885 virtual vec3 getPhysicalVelocity() = 0;
887 void setPhysicalVelocity(
vec3 velocity)
889 velocity_ = velocity;
909 virtual void transformationChanged(
const mat4 &m) = 0;
910 virtual void velocityChanged(
const vec3 &v) = 0;
976 virtual void renderObject()
992 virtual mat4 getPhysicalTransformation()
997 virtual vec3 getPhysicalVelocity()
1008 virtual void transformationChanged(
const mat4 &m) {}
1009 virtual void velocityChanged(
const vec3 &v) {}
1014 template<
typename T>
1059 return(
vec3(0,0,0));
1067 return(
vec3(0,0,0));
1089 virtual void renderObject()
1095 virtual void preupdateObject(
double dt)
1101 virtual void updateObject(
double dt)
1117 virtual mat4 getPhysicalTransformation()
1122 virtual vec3 getPhysicalVelocity()
1133 virtual void transformationChanged(
const mat4 &m) {}
1134 virtual void velocityChanged(
const vec3 &v) {}
1139 template<
typename T>
1159 virtual mat4 getPhysicalTransformation()
1164 virtual vec3 getPhysicalVelocity()
1175 virtual void transformationChanged(
const mat4 &m) {}
1176 virtual void velocityChanged(
const vec3 &v) {}
1181 template<
typename T>
1214 virtual mat4 getPhysicalTransformation()
1219 virtual vec3 getPhysicalVelocity()
1230 virtual void transformationChanged(
const mat4 &m) {}
1231 virtual void velocityChanged(
const vec3 &v) {}
1235 template<
typename T>
1240 typedef lgl_Objects::iterator iterator;
1259 T *data = pobj->createPhysicalData();
1260 pobj->setPhysicalData(data);
1270 iterator result =
end();
1271 double distance = radius;
1273 for (iterator it=
begin(); it!=
end(); it++)
1275 if (pobj->getPhysicalMass() > 0)
1277 double d = pobj->getDistanceToObject(center);
1294 objectRemoved(pobj);
1303 objectDeactivated(pobj, yes);
1344 updatePhysicalObjects(dt);
1346 for (iterator it=
begin(); it!=
end(); it++)
1350 mat4 m = pobj->getPhysicalTransformation();
1351 pobj->setPhysicalTransformation(m);
1353 vec3 v = pobj->getPhysicalVelocity();
1354 pobj->setPhysicalVelocity(v);
1364 virtual void updatePhysicalObjects(
double dt) = 0;
1375 virtual void updatePhysicalObjects(
double dt) {}
virtual double getNorm()
get object norm
Definition: glvertex_object.h:514
void setPhysicalRestitution(double restitution)
set physical restitution
Definition: glvertex_object.h:822
virtual void drawObjects()
draw all objects without updating
Definition: glvertex_object.h:691
virtual double getNorm()
get object norm
Definition: glvertex_object.h:340
virtual void updateObjects(double dt)
update all objects
Definition: glvertex_object.h:744
sphere object
Definition: glvertex_object.h:490
lglVBO * getVBO()
get vbo
Definition: glvertex_object.h:930
virtual void preupdateObjects(double dt)
pre-update all objects
Definition: glvertex_object.h:732
virtual vec3 getExtent()
get bounding box extent
Definition: glvertex_object.h:417
void preupdateSceneGraph(double dt)
pre-update the entire scene subgraph
Definition: glvertex_nodes.h:404
virtual vec3 getCenter()
get object barycenter relative to object position
Definition: glvertex_object.h:1054
void rotate(const quat &q)
rotate object by quaternion
Definition: glvertex_object.h:158
virtual void applyImpulse(vec3 impulse)=0
apply linear impulse to center of mass
virtual double getNorm()
get object norm
Definition: glvertex_object.h:1201
scene graph node (base class)
Definition: glvertex_nodes.h:22
graphical object class (base class)
Definition: glvertex_object.h:19
container class for multiple graphical objects
Definition: glvertex_object.h:584
mat3 getRotation()
get object rotation
Definition: glvertex_object.h:100
virtual void removeObject(iterator it)
remove physical object
Definition: glvertex_object.h:1291
virtual vec3 getExtent()
get bounding box extent
Definition: glvertex_object.h:949
vec4 getColor()
get object color
Definition: glvertex_object.h:44
virtual iterator addObject(lgl_Object *obj)
add physical object
Definition: glvertex_object.h:1255
virtual double getRadius()
get bounding object radius
Definition: glvertex_object.h:1196
virtual void applyImpulse(vec3 impulse)
apply linear impulse to center of mass
Definition: glvertex_object.h:1128
virtual void removeObject(iterator it)
remove graphical object
Definition: glvertex_object.h:653
lgl_Node * getSceneGraph()
get scene graph
Definition: glvertex_object.h:389
lgl_DepthSortedObjects()
ctor
Definition: glvertex_object.h:551
virtual double getNorm()
get object norm
Definition: glvertex_object.h:145
lgl_GeometryObject(lglVBO *vbo=NULL)
ctor
Definition: glvertex_object.h:296
bool hasTransparency()
get object transparency flag
Definition: glvertex_object.h:57
virtual double getNorm()
get object norm
Definition: glvertex_object.h:433
void scale(double factor)
scale object by factor
Definition: glvertex_object.h:164
virtual vec3 getCenter()
get object barycenter relative to object position
Definition: glvertex_object.h:409
lgl_Node * getSceneGraph()
get scene graph
Definition: glvertex_object.h:1034
physical cube object (base template)
Definition: glvertex_object.h:1140
lgl_SceneGraphObject(lgl_Node *root=NULL)
ctor
Definition: glvertex_object.h:375
virtual void applyTorque(vec3 torque)
apply angular impulse to center of mass
Definition: glvertex_object.h:1004
virtual void applyTorque(vec3 torque)
apply angular impulse to center of mass
Definition: glvertex_object.h:1171
virtual iterator addObject(lgl_Object *obj)
add graphical object
Definition: glvertex_object.h:603
4D double vector
Definition: glslmath.h:713
vec3 lglGetCenter() const
get the bounding box barycenter of the contained vertices in vbo
Definition: glvertex_core.h:1819
void setPhysicalData(T *data)
set physical data
Definition: glvertex_object.h:787
vec3 getCenter()
get the bounding box center of the entire subgraph
Definition: glvertex_nodes.h:483
void renderObjects(double dt=0)
render and update all objects
Definition: glvertex_object.h:675
vec3 getScale()
get object scale
Definition: glvertex_object.h:106
vec3 getPosition()
get object position
Definition: glvertex_object.h:94
virtual double getRadius()
get bounding object radius
Definition: glvertex_object.h:1070
double getRadius()
get the bounding sphere radius of the entire subgraph
Definition: glvertex_nodes.h:512
virtual double getNorm()
get object norm
Definition: glvertex_object.h:1078
void lglPopMatrix()
pop matrix (as defined by OpenGL 1.2)
Definition: glvertex_api.h:78
void lglColor(const vec4f &c)
specify vertex color attribute (as defined by OpenGL 1.2)
Definition: glvertex_api.h:30
virtual void applyForce(vec3 force, vec3 rel_pos=vec3(0, 0, 0))
apply force to point relative to center of mass
Definition: glvertex_object.h:1127
void setVelocity(vec3 velocity)
set object velocity
Definition: glvertex_object.h:871
double getMaxScale()
get maximum object scale
Definition: glvertex_object.h:112
iterator findObject(vec3 center, double radius)
find nearest graphical object within search radius
Definition: glvertex_object.h:620
bool hasPartialTransparency()
get partial object transparency flag
Definition: glvertex_object.h:69
void lglMultMatrix(const mat4 &matrix)
multiply with matrix (as defined by OpenGL 1.2)
Definition: glvertex_api.h:70
void move(const vec3 &delta)
move object by delta vector
Definition: glvertex_object.h:151
iterator end()
end iterator
Definition: glvertex_object.h:1313
virtual void applyImpulse(vec3 impulse)
apply linear impulse to center of mass
Definition: glvertex_object.h:1225
virtual void drawObjects(vec3 eye)
draw all objects with depth sorting
Definition: glvertex_object.h:559
virtual void deactivateObject(iterator it, bool yes=true)
deactivate physical object
Definition: glvertex_object.h:1300
virtual double getDistanceToObject(const vec3 &v)
compute minimum distance to transformed object
Definition: glvertex_object.h:462
physical object (base template)
Definition: glvertex_object.h:762
virtual void applyForce(vec3 force, vec3 rel_pos=vec3(0, 0, 0))
apply force to point relative to center of mass
Definition: glvertex_object.h:1002
iterator findNonStaticObject(vec3 center, double radius)
find nearest non-static graphical object within search radius
Definition: glvertex_object.h:1268
lgl_Object()
ctor
Definition: glvertex_object.h:24
iterator findObject(lgl_Object *obj)
find graphical object
Definition: glvertex_object.h:610
void renderObjects(vec3 eye, double dt=0)
render and update all objects
Definition: glvertex_object.h:683
3D double vector
Definition: glslmath.h:372
double getPhysicalMass()
get physical mass
Definition: glvertex_object.h:803
double lglGetNorm() const
get the bounding sphere norm of the contained vertices in vbo
Definition: glvertex_core.h:1844
virtual void updateObjects(double dt)
update all objects
Definition: glvertex_object.h:1342
void updateSceneGraph(double dt)
update the entire scene subgraph
Definition: glvertex_nodes.h:410
static double getDistanceToSphere(const vec3 &p, const vec3 &v, double radius)
compute minimum distance to sphere
Definition: glvertex_object.h:242
bool shown()
is the object shown?
Definition: glvertex_object.h:182
4x4 double matrix
Definition: glslmath.h:2116
void hasPartialTransparency(bool flag)
set partial object transparency flag
Definition: glvertex_object.h:75
mat3 getRotation() const
get 3x3 rotation submatrix (matrix is assumed to be orthonormal)
Definition: glslmath.h:2290
double lglGetRadius() const
get the bounding sphere radius of the contained vertices in vbo
Definition: glvertex_core.h:1832
void setColor(const vec4 &c)
set object color
Definition: glvertex_object.h:50
virtual vec3 getCenter()
get object barycenter relative to object position
Definition: glvertex_object.h:127
no physical geometry object (empty physics implementation)
Definition: glvertex_object.h:988
virtual void applyForce(vec3 force, vec3 rel_pos=vec3(0, 0, 0))
apply force to point relative to center of mass
Definition: glvertex_object.h:1224
virtual vec3 getCenter()
get object barycenter relative to object position
Definition: glvertex_object.h:316
iterator begin()
begin iterator
Definition: glvertex_object.h:1307
virtual double getRadius()
get bounding object radius
Definition: glvertex_object.h:957
physical geometry object (base template)
Definition: glvertex_object.h:916
lgl_CubeObject()
ctor
Definition: glvertex_object.h:479
lgl_PhysicalSceneGraphObject(lgl_Node *root=NULL)
ctor
Definition: glvertex_object.h:1020
virtual double getDistanceToObject(const vec3 &v)
compute minimum distance to transformed object
Definition: glvertex_object.h:214
void show(bool yes=true)
show object
Definition: glvertex_object.h:194
lgl_Objects()
ctor
Definition: glvertex_object.h:591
void setSceneGraph(lgl_Node *root)
set scene graph
Definition: glvertex_object.h:1040
T * getPhysicalData()
get physical data
Definition: glvertex_object.h:781
unit cube vbo
Definition: glvertex_geometry.h:19
virtual double getRadius()
get bounding object radius
Definition: glvertex_object.h:425
iterator end()
end iterator
Definition: glvertex_object.h:669
double getNorm()
get the bounding sphere norm of the entire subgraph
Definition: glvertex_nodes.h:527
virtual double getRadius()
get bounding object radius
Definition: glvertex_object.h:139
virtual double getRadius()
get bounding object radius
Definition: glvertex_object.h:509
virtual vec3 getCenter()
get object barycenter relative to object position
Definition: glvertex_object.h:941
unit sphere vbo
Definition: glvertex_geometry.h:653
virtual void applyTorque(vec3 torque)
apply angular impulse to center of mass
Definition: glvertex_object.h:1226
cube object
Definition: glvertex_object.h:474
lgl_PhysicalSphereObject()
ctor
Definition: glvertex_object.h:1187
virtual void lglRender(const lgl *vbo=NULL)
render the series of vertices contained in vbo
Definition: glvertex_core.h:1079
static double getDistanceToBox(const vec3 &p, const mat3 &rotation, const vec3 &offset, const vec3 &v, const vec3 &ext)
compute minimum distance to rotated and displaced box
Definition: glvertex_object.h:280
void hasTransparency(bool flag)
set object transparency flag
Definition: glvertex_object.h:63
quaternion
Definition: glslmath.h:2972
iterator getSelectedObject()
get selected graphical object
Definition: glvertex_object.h:647
virtual double getDistanceToObject(const vec3 &v)
compute minimum distance to transformed object
Definition: glvertex_object.h:502
iterator begin()
begin iterator
Definition: glvertex_object.h:663
static double getDistanceToBox(const vec3 &p, const mat3 &rotation, const vec3 &v, const vec3 &ext)
compute minimum distance to rotated box
Definition: glvertex_object.h:274
bool hidden()
is the object hidden?
Definition: glvertex_object.h:176
double length() const
get vector length
Definition: glslmath.h:420
mat4 getTransformation()
get object transformation
Definition: glvertex_object.h:81
lgl_SphereObject()
ctor
Definition: glvertex_object.h:495
virtual void applyForce(vec3 force, vec3 rel_pos=vec3(0, 0, 0))
apply force to point relative to center of mass
Definition: glvertex_object.h:1169
geometry object
Definition: glvertex_object.h:291
LGL API: vbo class definition.
Definition: glvertex_core.h:5827
void selectObject(iterator it)
select graphical object
Definition: glvertex_object.h:641
container class for multiple physical objects (base template)
Definition: glvertex_object.h:1236
3x3 double matrix
Definition: glslmath.h:1544
void setSceneGraph(lgl_Node *root)
set scene graph
Definition: glvertex_object.h:395
no physical cube object (empty physics implementation)
Definition: glvertex_object.h:1155
lglVBO * getVBO()
get vbo
Definition: glvertex_object.h:305
physical scene graph object (base template)
Definition: glvertex_object.h:1015
void setVBO(lglVBO *vbo)
set vbo
Definition: glvertex_object.h:311
virtual void applyTorque(vec3 torque)=0
apply angular impulse to center of mass
physical sphere object (base template)
Definition: glvertex_object.h:1182
vec3 getExtent()
get the bounding box extent of the entire subgraph
Definition: glvertex_nodes.h:497
lgl_PhysicalObjects()
ctor
Definition: glvertex_object.h:1243
void lglZWrite(bool on=true)
change OpenGL state (depth write)
Definition: glvertex_api.h:380
no physical scene graph object (empty physics implementation)
Definition: glvertex_object.h:1113
vec3 lglGetExtent() const
get the bounding box extent of the contained vertices in vbo
Definition: glvertex_core.h:1825
void lglPushMatrix()
push matrix (as defined by OpenGL 1.2)
Definition: glvertex_api.h:74
virtual double getDistanceToObject(const vec3 &v)
compute minimum distance to transformed object
Definition: glvertex_object.h:357
bool hasTransparency()
check the entire subgraph whether or not it contains semi-transparent geometry
Definition: glvertex_nodes.h:628
virtual vec3 getExtent()
get bounding box extent
Definition: glvertex_object.h:133
virtual vec3 getExtent()
get bounding box extent
Definition: glvertex_object.h:1062
no physical sphere object (empty physics implementation)
Definition: glvertex_object.h:1210
bool hasUniformScale()
object has uniform scale?
Definition: glvertex_object.h:121
void setVBO(lglVBO *vbo)
set vbo
Definition: glvertex_object.h:936
void setGravity(double g)
set gravity
Definition: glvertex_object.h:1329
void lglScale(const vec4 &c)
multiply with scale matrix (as defined by OpenGL 1.2)
Definition: glvertex_api.h:82
bool lglGetZWrite()
get OpenGL state (depth write)
Definition: glvertex_api.h:384
virtual double getRadius()
get bounding object radius
Definition: glvertex_object.h:332
vec3 getTranslation() const
get translation column vector (matrix is assumed to be affine)
Definition: glslmath.h:2294
virtual double getNorm()
get object norm
Definition: glvertex_object.h:965
lgl_PhysicalGeometryObject(lglVBO *vbo=NULL)
ctor
Definition: glvertex_object.h:921
mat3 invert() const
invert 3x3 matrix
Definition: glslmath.h:1723
void setPhysicalMass(double mass)
set physical mass a mass of zero creates a static (immovable) object
Definition: glvertex_object.h:810
scene graph object
Definition: glvertex_object.h:370
static mat4 translate(double x, double y, double z)
create translation matrix
Definition: glslmath.h:2427
void renderTransformedObject()
render transformed object
Definition: glvertex_object.h:200
vec3 getVelocity()
get object velocity
Definition: glvertex_object.h:880
virtual void applyImpulse(vec3 impulse)
apply linear impulse to center of mass
Definition: glvertex_object.h:1170
void setTransformation(const mat4 &m)
set object transformation
Definition: glvertex_object.h:87
lgl_PhysicalCubeObject()
ctor
Definition: glvertex_object.h:1145
void drawSceneGraph(vec4 color=vec4(1))
draw the entire scene subgraph without updating
Definition: glvertex_nodes.h:359
virtual T * createPhysicalData()
create physical data
Definition: glvertex_object.h:797
static double getDistanceToBox(const vec3 &p, const vec3 &v, const vec3 &ext)
compute minimum distance to box
Definition: glvertex_object.h:250
virtual void applyForce(vec3 force, vec3 rel_pos=vec3(0, 0, 0))=0
apply force to point relative to center of mass
virtual vec3 getExtent()
get bounding box extent
Definition: glvertex_object.h:324
double getPhysicalRestitution()
get physical restitution
Definition: glvertex_object.h:816
virtual void drawObjects(vec3 eye)
draw all objects with depth sorting
Definition: glvertex_object.h:703
container class for multiple depth-sorted graphical objects
Definition: glvertex_object.h:544
void hide(bool yes=true)
hide object
Definition: glvertex_object.h:188
virtual void applyImpulse(vec3 impulse)
apply linear impulse to center of mass
Definition: glvertex_object.h:1003
lgl_PhysicalObject()
ctor
Definition: glvertex_object.h:767
void setGroundPlane(vec3 o, vec3 n, double r=1.0)
set ground plane
Definition: glvertex_object.h:1321
container class for multiple non-physical objects (empty physics implementation)
Definition: glvertex_object.h:1368
virtual void applyTorque(vec3 torque)
apply angular impulse to center of mass
Definition: glvertex_object.h:1129
void scale(const vec3 &factor)
scale object by non-uniform factor
Definition: glvertex_object.h:170