More work on moving track objects via scripting
This commit is contained in:
parent
4070933364
commit
f992b864e1
@ -261,9 +261,12 @@ void TrackObject::init(const XMLNode &xml_node, scene::ISceneNode* parent,
|
||||
this);
|
||||
}
|
||||
|
||||
if (is_movable && parent_library != NULL)
|
||||
if (parent_library != NULL)
|
||||
{
|
||||
parent_library->addMovableChild(this);
|
||||
if (is_movable)
|
||||
parent_library->addMovableChild(this);
|
||||
else
|
||||
parent_library->addChild(this);
|
||||
}
|
||||
|
||||
video::SColor glow;
|
||||
@ -430,25 +433,32 @@ void TrackObject::move(const core::vector3df& xyz, const core::vector3df& hpr,
|
||||
|
||||
if (update_rigid_body && m_physical_object != NULL)
|
||||
{
|
||||
// If we set a bullet position from an irrlicht position, we need to
|
||||
// get the absolute transform from the presentation object (as set in
|
||||
// the line before), since xyz etc here are only relative to a
|
||||
// potential parent scene node.
|
||||
TrackObjectPresentationSceneNode *tops =
|
||||
dynamic_cast<TrackObjectPresentationSceneNode*>(m_presentation);
|
||||
if(tops)
|
||||
{
|
||||
const core::matrix4 &m = tops->getNode()
|
||||
->getAbsoluteTransformation();
|
||||
m_physical_object->move(m.getTranslation(),m.getRotationDegrees());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_physical_object->move(xyz, hpr);
|
||||
}
|
||||
movePhysicalBodyToGraphicalNode(xyz, hpr);
|
||||
}
|
||||
} // move
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void TrackObject::movePhysicalBodyToGraphicalNode(const core::vector3df& xyz, const core::vector3df& hpr)
|
||||
{
|
||||
// If we set a bullet position from an irrlicht position, we need to
|
||||
// get the absolute transform from the presentation object (as set in
|
||||
// the line before), since xyz etc here are only relative to a
|
||||
// potential parent scene node.
|
||||
TrackObjectPresentationSceneNode *tops =
|
||||
dynamic_cast<TrackObjectPresentationSceneNode*>(m_presentation);
|
||||
if (tops)
|
||||
{
|
||||
const core::matrix4 &m = tops->getNode()
|
||||
->getAbsoluteTransformation();
|
||||
m_physical_object->move(m.getTranslation(), m.getRotationDegrees());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_physical_object->move(xyz, hpr);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
const core::vector3df& TrackObject::getPosition() const
|
||||
{
|
||||
@ -496,3 +506,37 @@ void TrackObject::addMovableChild(TrackObject* child)
|
||||
child->setEnabled(false);
|
||||
m_movable_children.push_back(child);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void TrackObject::addChild(TrackObject* child)
|
||||
{
|
||||
if (!m_enabled)
|
||||
child->setEnabled(false);
|
||||
m_children.push_back(child);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// scripting function
|
||||
void TrackObject::moveTo(const Scripting::SimpleVec3* pos, bool isAbsoluteCoord)
|
||||
{
|
||||
TrackObjectPresentationLibraryNode *libnode =
|
||||
dynamic_cast<TrackObjectPresentationLibraryNode*>(m_presentation);
|
||||
if (libnode != NULL)
|
||||
{
|
||||
libnode->move(core::vector3df(pos->getX(), pos->getY(), pos->getZ()),
|
||||
core::vector3df(0.0f, 0.0f, 0.0f), // TODO: preserve rotation
|
||||
core::vector3df(1.0f, 1.0f, 1.0f), // TODO: preserve scale
|
||||
isAbsoluteCoord,
|
||||
true /* moveChildrenPhysicalBodies */);
|
||||
}
|
||||
else
|
||||
{
|
||||
move(core::vector3df(pos->getX(), pos->getY(), pos->getZ()),
|
||||
core::vector3df(0.0f, 0.0f, 0.0f), // TODO: preserve rotation
|
||||
core::vector3df(1.0f, 1.0f, 1.0f), // TODO: preserve scale
|
||||
true, // updateRigidBody
|
||||
isAbsoluteCoord);
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +94,7 @@ protected:
|
||||
TrackObject* m_parent_library;
|
||||
|
||||
std::vector<TrackObject*> m_movable_children;
|
||||
std::vector<TrackObject*> m_children;
|
||||
|
||||
bool m_initially_visible;
|
||||
|
||||
@ -214,14 +215,7 @@ public:
|
||||
/** Hide or show the object */
|
||||
void setEnabled(bool mode);
|
||||
|
||||
void moveTo(const Scripting::SimpleVec3* pos, bool isAbsoluteCoord)
|
||||
{
|
||||
move(core::vector3df(pos->getX(), pos->getY(), pos->getZ()),
|
||||
core::vector3df(0.0f, 0.0f, 0.0f), // TODO: preserve rotation
|
||||
core::vector3df(1.0f, 1.0f, 1.0f), // TODO: preserve scale
|
||||
true, // updateRigidBody
|
||||
isAbsoluteCoord);
|
||||
}
|
||||
void moveTo(const Scripting::SimpleVec3* pos, bool isAbsoluteCoord);
|
||||
/* @} */
|
||||
/* @} */
|
||||
/* @} */
|
||||
@ -241,7 +235,14 @@ public:
|
||||
* to still preserve the parent-child relationship
|
||||
*/
|
||||
void addMovableChild(TrackObject* child);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
void addChild(TrackObject* child);
|
||||
// ------------------------------------------------------------------------
|
||||
std::vector<TrackObject*>& getMovableChildren() { return m_movable_children; }
|
||||
// ------------------------------------------------------------------------
|
||||
std::vector<TrackObject*>& getChildren() { return m_children; }
|
||||
// ------------------------------------------------------------------------
|
||||
void movePhysicalBodyToGraphicalNode(const core::vector3df& xyz, const core::vector3df& hpr);
|
||||
LEAK_CHECK()
|
||||
}; // TrackObject
|
||||
|
||||
|
@ -254,6 +254,7 @@ TrackObjectPresentationLibraryNode::TrackObjectPresentationLibraryNode(
|
||||
assert(libroot != NULL);
|
||||
World::getWorld()->getTrack()->loadObjects(libroot, lib_path, model_def_loader,
|
||||
create_lod_definitions, m_node, parent);
|
||||
m_parent = parent;
|
||||
} // TrackObjectPresentationLibraryNode
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -261,7 +262,24 @@ TrackObjectPresentationLibraryNode::~TrackObjectPresentationLibraryNode()
|
||||
{
|
||||
irr_driver->removeNode(m_node);
|
||||
} // TrackObjectPresentationLibraryNode
|
||||
// ----------------------------------------------------------------------------
|
||||
void TrackObjectPresentationLibraryNode::move(const core::vector3df& xyz, const core::vector3df& hpr,
|
||||
const core::vector3df& scale, bool isAbsoluteCoord, bool moveChildrenPhysicalBodies)
|
||||
{
|
||||
TrackObjectPresentationSceneNode::move(xyz, hpr, scale, isAbsoluteCoord);
|
||||
|
||||
if (moveChildrenPhysicalBodies)
|
||||
{
|
||||
for (TrackObject* obj : m_parent->getChildren())
|
||||
{
|
||||
obj->reset();
|
||||
if (obj->getPhysicalObject() != NULL)
|
||||
{
|
||||
obj->movePhysicalBodyToGraphicalNode(obj->getAbsolutePosition(), obj->getRotation());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
||||
TrackObjectPresentationLOD::TrackObjectPresentationLOD(const XMLNode& xml_node,
|
||||
scene::ISceneNode* parent,
|
||||
|
@ -174,11 +174,14 @@ public:
|
||||
*/
|
||||
class TrackObjectPresentationLibraryNode : public TrackObjectPresentationSceneNode
|
||||
{
|
||||
TrackObject* m_parent;
|
||||
public:
|
||||
TrackObjectPresentationLibraryNode(TrackObject* parent,
|
||||
const XMLNode& xml_node,
|
||||
ModelDefinitionLoader& model_def_loader);
|
||||
virtual ~TrackObjectPresentationLibraryNode();
|
||||
void move(const core::vector3df& xyz, const core::vector3df& hpr,
|
||||
const core::vector3df& scale, bool isAbsoluteCoord, bool moveChildrenPhysicalBodies);
|
||||
}; // TrackObjectPresentationLibraryNode
|
||||
|
||||
// ============================================================================
|
||||
|
Loading…
x
Reference in New Issue
Block a user