
Moderators: Sascha Willems, walaber
Julio Jerez wrote:If you have time could and you or Pjani use any kind of Collada Viewer, could to please try and see if it work, Collada file format is all wacky and no all loaders supports all of the possibilities to encode a mesh.
This is a plain vanilla for now so it must be compatible with almost all viewers.
Julio Jerez wrote:About the mutiobody car , Netwon 2 has a mutibody car joint, I have no added yet because I wnat for finish all Ogre Newton Funtionality before we move wih new funtionality.
But yet there will be a Mutibody car wraped joint from Newton to Ogre newton.
class MyCustomBallSocket : public OgreNewt::BallAndSocket
#ifndef LOCKEDDIFFERENTIAL_H_INCLUDED
#define LOCKEDDIFFERENTIAL_H_INCLUDED
#include <OgreNewt.h>
#include "OgreNewtExtensions.h"
namespace VD
{
namespace Vehicle
{
class LockedDifferential : public OgreNewt::Joint
{
public:
LockedDifferential(OgreNewt::BodyPtr child, OgreNewt::BodyPtr parent, Ogre::Vector3 pin);
~LockedDifferential();
void submitConstraint(Ogre::Real timeStep, int threadIndex);
private:
Ogre::Vector3 localChildPosition;
Ogre::Vector3 localParentPosition;
Ogre::Quaternion localChildOrientation;
Ogre::Quaternion localParentOrientation;
Ogre::Vector3 pin;
};
} // namespace Vehicle
} // namespace VD
#endif // LOCKEDDIFFERENTIAL_H_INCLUDED
#include "Vehicle/LockedDifferential.h"
#include "Debug/VectorDebugger.h"
#define MIN_JOINT_PIN_LENGTH -1.5f
#include "MemoryLeakDetection.h"
namespace VD
{
namespace Vehicle
{
LockedDifferential::LockedDifferential(OgreNewt::BodyPtr child, OgreNewt::BodyPtr parent, Ogre::Vector3 pin) : OgreNewt::CustomJoint(1, child.get(), parent.get())
{
this->pin = pin;
Ogre::Vector3 parentPosition, childPosition;
Ogre::Quaternion parentOrientation, childOrientation;
m_body0->getPositionOrientation(childPosition, childOrientation);
m_body1->getPositionOrientation(parentPosition, parentOrientation);
pinAndDirToLocal(childPosition, pin, localChildOrientation, localChildPosition, localParentOrientation, localParentPosition);
}
LockedDifferential::~LockedDifferential()
{
}
void LockedDifferential::submitConstraint(Ogre::Real timeStep, int threadIndex)
{
Ogre::Quaternion globalChildOrientation, globalParentOrientation;
Ogre::Vector3 globalChildPosition, globalParentPosition;
localToGlobal(localChildOrientation, localChildPosition, globalChildOrientation, globalChildPosition, 0);
localToGlobal(localParentOrientation, localParentPosition, globalParentOrientation, globalParentPosition, 1);
Ogre::Vector3 childOmega = m_body0->getOmega();
Ogre::Vector3 parentOmega = m_body1->getOmega();
float childAngularVelocity = childOmega.dotProduct(globalChildOrientation * Ogre::Vector3::UNIT_X);
float parentAngularVelocity = parentOmega.dotProduct(globalParentOrientation * -Ogre::Vector3::UNIT_X);
float relativeOmega = childAngularVelocity + (1.0f * parentAngularVelocity);
float relativeAcceleration = -0.3f * relativeOmega / timeStep;
addGeneralRow(Ogre::Vector3::ZERO, globalChildOrientation * Ogre::Vector3::UNIT_X, Ogre::Vector3::ZERO, globalParentOrientation * -Ogre::Vector3::UNIT_X);
setRowAcceleration(relativeAcceleration);
}
} // namespace Vehicle
} // namespace VD
class _OgreNewtExport CustomJoint : public Joint
{
public:
CustomJoint( unsigned int maxDOF, const OgreNewt::Body* child, const OgreNewt::Body* parent);
virtual ~CustomJoint();
void pinAndDirToLocal( const Ogre::Vector3& pinpt, const Ogre::Vector3& pindir, Ogre::Quaternion& localOrient0, Ogre::Vector3& localPos0, Ogre::Quaternion& localOrient1, Ogre::Vector3& localPos1 ) const;
void localToGlobal( const Ogre::Quaternion& localOrient, const Ogre::Vector3& localPos, Ogre::Quaternion& globalOrient, Ogre::Vector3& globalPos, int bodyIndex ) const;
void globalToLocal( const Ogre::Quaternion& globalOrient, const Ogre::Vector3& globalPos, Ogre::Quaternion& localOrient, Ogre::Vector3& localPos, int bodyIndex ) const;
Ogre::Quaternion grammSchmidt( const Ogre::Vector3& pin ) const;
protected:
unsigned int m_maxDOF;
const OgreNewt::Body* m_body0;
const OgreNewt::Body* m_body1;
};
CustomJoint::CustomJoint( unsigned int maxDOF, const Body* child, const Body* parent ) : Joint()
{
NewtonCustomJoint* suppportJoint;
suppportJoint = new CustomUserJoint(maxDOF, child->getNewtonBody(), parent ? parent->getNewtonBody() : NULL);
SetSupportJoint(suppportJoint);
m_maxDOF = maxDOF;
m_body0 = child;
m_body1 = parent;
}
CustomJoint::~CustomJoint()
{
}
void CustomJoint::pinAndDirToLocal( const Ogre::Vector3& pinpt, const Ogre::Vector3& pindir,
Ogre::Quaternion& localOrient0, Ogre::Vector3& localPos0, Ogre::Quaternion& localOrient1, Ogre::Vector3& localPos1 ) const
{
localOrient0 = localOrient1 = Ogre::Quaternion::IDENTITY;
localPos0 = localPos1 = Ogre::Vector3::ZERO;
Ogre::Quaternion bodyOrient0 = Ogre::Quaternion::IDENTITY;
Ogre::Quaternion bodyOrient1 = Ogre::Quaternion::IDENTITY;
Ogre::Vector3 bodyPos0 = Ogre::Vector3::ZERO;
Ogre::Vector3 bodyPos1 = Ogre::Vector3::ZERO;
Ogre::Quaternion pinOrient = grammSchmidt(pindir);
getBody0()->getPositionOrientation( bodyPos0, bodyOrient0 );
if (getBody1() != NULL)
{
getBody1()->getPositionOrientation( bodyPos1, bodyOrient1 );
}
localPos0 = bodyOrient0.Inverse() * (pinpt - bodyPos0);
localOrient0 = pinOrient * bodyOrient0.Inverse();
localPos1 = bodyOrient1.Inverse() * (pinpt - bodyPos1);
localOrient1 = pinOrient * bodyOrient1.Inverse();
}
void CustomJoint::localToGlobal( const Ogre::Quaternion& localOrient, const Ogre::Vector3& localPos, Ogre::Quaternion& globalOrient, Ogre::Vector3& globalPos, int bodyIndex ) const
{
globalOrient = Ogre::Quaternion::IDENTITY;
globalPos= Ogre::Vector3::ZERO;
const Body* bdy = NULL;
if (bodyIndex == 0)
bdy = getBody0();
else if (getBody1())
bdy = getBody1();
Ogre::Quaternion bodyOrient = Ogre::Quaternion::IDENTITY;
Ogre::Vector3 bodyPos = Ogre::Vector3::ZERO;
if (bdy)
{
bdy->getPositionOrientation( bodyPos, bodyOrient );
}
globalPos = (bodyOrient * localPos) + bodyPos;
globalOrient = bodyOrient * localOrient;
}
void CustomJoint::globalToLocal( const Ogre::Quaternion& globalOrient, const Ogre::Vector3& globalPos, Ogre::Quaternion& localOrient, Ogre::Vector3& localPos, int bodyIndex ) const
{
localOrient = Ogre::Quaternion::IDENTITY;
localPos= Ogre::Vector3::ZERO;
const Body* bdy = NULL;
if (bodyIndex == 0)
bdy = getBody0();
else if (getBody1() != NULL)
bdy = getBody1();
Ogre::Quaternion bodyOrient = Ogre::Quaternion::IDENTITY;
Ogre::Vector3 bodyPos = Ogre::Vector3::ZERO;
if (bdy)
bdy->getPositionOrientation( bodyPos, bodyOrient );
Ogre::Quaternion bodyOrientInv = bodyOrient.Inverse();
localOrient = bodyOrientInv * globalOrient;
localPos = bodyOrientInv * (globalPos - bodyPos);
}
Ogre::Quaternion CustomJoint::grammSchmidt( const Ogre::Vector3& pin ) const
{
Ogre::Vector3 front, up, right;
front = pin;
front.normalise();
if (Ogre::Math::Abs( front.z ) > 0.577f)
right = front.crossProduct( Ogre::Vector3(-front.y, front.z, 0.0f) );
else
right = front.crossProduct( Ogre::Vector3(-front.y, front.x, 0.0f) );
right.normalise();
up = right.crossProduct( front );
Ogre::Matrix3 ret;
ret.FromAxes( front, up, right );
Ogre::Quaternion quat;
quat.FromRotationMatrix( ret );
return quat;
}
/* Copyright (c) <2009> <Newton Game Dynamics>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely
*/
// CustomUserJoint.h: interface for the CustomUserJoint class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CUSTOMUSERJOINT_H__B631F556_468B_4331_B7D7_F85ECF3E9ADE__INCLUDED_)
#define AFX_CUSTOMUSERJOINT_H__B631F556_468B_4331_B7D7_F85ECF3E9ADE__INCLUDED_
#include "NewtonCustomJoint.h"
class JOINTLIBRARY_API CustomUserJoint: public NewtonCustomJoint
{
public:
CustomUserJoint(unsigned int maxDOF, const NewtonBody* child, const NewtonBody* parent = NULL);
virtual ~CustomUserJoint();
protected:
virtual void SubmitConstraints (dFloat timestep, int threadIndex);
virtual void GetInfo (NewtonJointRecord* info) const;
};
#endif // !defined(AFX_CUSTOMUSERJOINT_H__B631F556_468B_4331_B7D7_F85ECF3E9ADE__INCLUDED_)
/* Copyright (c) <2009> <Newton Game Dynamics>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely
*/
// CustomUserJoint.cpp: implementation of the CustomUserJoint class.
//
//////////////////////////////////////////////////////////////////////
#include "CustomJointLibraryStdAfx.h"
#include "CustomUserJoint.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#define MIN_JOINT_PIN_LENGTH 50.0f
CustomUserJoint::CustomUserJoint(unsigned int maxDOF, const NewtonBody* child, const NewtonBody* parent)
:NewtonCustomJoint(maxDOF, child, parent)
{
}
CustomUserJoint::~CustomUserJoint()
{
}
void CustomUserJoint::GetInfo (NewtonJointRecord* info) const
{
strcpy (info->m_descriptionType, "customuser");
info->m_attachBody_0 = m_body0;
info->m_attachBody_1 = m_body1;
info->m_minLinearDof[0] = 0.0f;
info->m_maxLinearDof[0] = 0.0f;
info->m_minLinearDof[1] = 0.0f;
info->m_maxLinearDof[1] = 0.0f;;
info->m_minLinearDof[2] = 0.0f;
info->m_maxLinearDof[2] = 0.0f;
info->m_minAngularDof[0] = -FLT_MAX ;
info->m_maxAngularDof[0] = FLT_MAX ;
info->m_minAngularDof[1] = -FLT_MAX ;
info->m_maxAngularDof[1] = FLT_MAX ;
info->m_minAngularDof[2] = -FLT_MAX ;
info->m_maxAngularDof[2] = FLT_MAX ;
}
void CustomUserJoint::SubmitConstraints (dFloat timestep, int threadIndex)
{
}
kallaspriit wrote:I realize we have broken the existing custom joint interface so any custom joints, that users have created, do not work anymore.
class _OgreNewtExport CustomJoint : public Joint
{
public:
CustomJoint( unsigned int maxDOF, const OgreNewt::Body* child, const OgreNewt::Body* parent);
virtual ~CustomJoint();
void pinAndDirToLocal( const Ogre::Vector3& pinpt, const Ogre::Vector3& pindir, Ogre::Quaternion& localOrient0, Ogre::Vector3& localPos0, Ogre::Quaternion& localOrient1, Ogre::Vector3& localPos1 ) const;
void localToGlobal( const Ogre::Quaternion& localOrient, const Ogre::Vector3& localPos, Ogre::Quaternion& globalOrient, Ogre::Vector3& globalPos, int bodyIndex ) const;
void globalToLocal( const Ogre::Quaternion& globalOrient, const Ogre::Vector3& globalPos, Ogre::Quaternion& localOrient, Ogre::Vector3& localPos, int bodyIndex ) const;
Ogre::Quaternion grammSchmidt( const Ogre::Vector3& pin ) const;
protected:
unsigned int m_maxDOF;
const OgreNewt::Body* m_body0;
const OgreNewt::Body* m_body1;
};
Users browsing this forum: No registered users and 1 guest