Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

RigidBodyPoint.cpp

00001 /*************************************************************************** 00002 * This file is part of OpenCAL: Open Computer Animation Library * 00003 * I created OpenCAL as my master's thesis Computer Science (multimedia) * 00004 * at the tUL university in Diepenbeek, Belgium * 00005 * * 00006 * Copyright (C) 2003-2004 by Jeroen Dierckx * 00007 * jeroen.dierckx@student.luc.ac.be * 00008 * * 00009 ***************************************************************************/ 00010 00011 // Includes 00012 #include "RigidBodyPoint.h" 00013 #include <OpenCAL/System.h> 00014 #include <OpenCAL/Renderer.h> 00015 #include <OpenCAL/RigidBody.h> 00016 using namespace OpenCAL; 00017 00018 using namespace std; 00019 00020 00021 /****************************** 00022 * Constructors and destructor * 00023 ******************************/ 00024 00025 RigidBodyPoint::RigidBodyPoint(RigidBody *object, const Vector3 &bodyPosition) 00026 : PhysicalObject(object->getParent()), m_object(object), m_bodyPosition(bodyPosition) 00027 { 00028 // Don't draw this by default 00029 m_draw = false; 00030 m_oneOverMass = 0.0f; 00031 } 00032 00033 RigidBodyPoint::~RigidBodyPoint() 00034 { 00035 } 00036 00037 00038 /****************** 00039 * Other functions * 00040 ******************/ 00041 00042 void RigidBodyPoint::addForce(const Vector3 &force) 00043 { 00045 m_object->addForce(force, m_bodyPosition); 00046 } 00047 00048 void RigidBodyPoint::render() 00049 { 00050 Renderer *renderer = m_parent->getRenderer(); 00051 if(!renderer) return; 00052 00053 renderer->renderPoint(getPosition(), 2.0f); 00054 } 00055 00056 void RigidBodyPoint::calcPosition() const 00057 { 00058 m_position = m_bodyPosition.rotated(m_object->getRotation()) + m_object->getPosition(); 00059 } 00060 00061 void RigidBodyPoint::calcVelocity() const 00062 { 00063 // Get the rotation matrix 00064 Matrix33 rot = m_object->getRotation().normalized().toMatrix33(); 00065 00066 // Get the inversed inertia tensor (in world coördinates) 00067 Matrix33 invInertia = rot * m_object->getInvInertia() * rot.transposed(); 00068 00069 // Get the angular velocity 00070 Vector3 omega = invInertia * m_object->getAngularMomentum(); 00071 00072 // Calculate the velocity 00073 m_velocity = omega.crossProduct(m_bodyPosition) + m_object->getVelocity(); 00074 }

Generated on Sun Aug 15 19:19:23 2004 for OpenCAL: Open Computer Animation Library by doxygen 1.3.8