c++ - How do I access a custom type once it is passed to another object? -
i'm new c++ excuse me if use of terminology off.
i'm writing app in openframeworks makes use of physics library called ofxmsaphysics. purposes, i've created custom class called "particle," inherits msaphysics particle3d class.
here pass pointer custom object physics engine:
particle * p = new particle(ofvec3f(gettokencoors(index))); physics.addparticle(p);
in custom class have public member called collide set true when 1 particle collides another. this, override 1 of particle3d's virtual methods:
void collidedwithparticle(particlet *other, ofvec3f collisionforce) { collide = true; }
now i'd check see when 1 particle collides another. physics.getparticle(i)
returns particle physics engine, 1 of type particle3d
, , not of custom particle type. when loop through particles returned getparticle()
, none of them contain "collide" variable.
is there way access custom particles once added engine?
please let me know if can clarify something.
edit: collidedwithparticle() virtual member of particle3d. had overridden method set collide true see if worked.
if you're sure particles in system of overiden type, can cast particle3d
particle
using
particle* myparticle = static_cast<particle*>(other);
but way isn't of safest ones, i'd suggest you, if possible check maybe there methods override in particle3d
class enable see if particle collided or save list of particles , use list sure particles of inherited type.
of course dynamic_cast
more appropriate , more safe, don't suggest using because of rtti, since rtti heavily slows down code execution.
Comments
Post a Comment