void OgrePointSpecification::setLocalOrientation(const Vector3& ori)
{
	Ogre::Matrix3 m;
	m.FromEulerAnglesXYZ(Ogre::Radian(ori.x),Ogre::Radian(ori.y),Ogre::Radian(ori.z));
	Ogre::Quaternion q(m);
	_node->setOrientation(q);
	_node->_update(true,true);
}
void OgrePointSpecification::rotate(const Vector3& orientation)
{
	Ogre::Matrix3 m;
	m.FromEulerAnglesXYZ(Ogre::Radian(orientation.x),Ogre::Radian(orientation.y),Ogre::Radian(orientation.z));
	Ogre::Quaternion q(m);
	_node->rotate(q,Ogre::Node::TS_LOCAL);
	_node->_update(true,true);
}
Ogre::Quaternion LuaScriptUtilities::QuaternionFromRotationDegrees(
    Ogre::Real xRotation, Ogre::Real yRotation, Ogre::Real zRotation)
{
    Ogre::Matrix3 matrix;
    matrix.FromEulerAnglesXYZ(
        Ogre::Degree(xRotation), Ogre::Degree(yRotation), Ogre::Degree(zRotation));
    return Ogre::Quaternion(matrix);
}
void OgrePointSpecification::setGlobalOrientation(const Vector3& ori)
{
	Ogre::Matrix3 m;
	m.FromEulerAnglesXYZ(Ogre::Radian(ori.x),Ogre::Radian(ori.y),Ogre::Radian(ori.z));
	Ogre::Quaternion q(m);
	if(_parent)
		q=shared_dynamic_cast<OgrePointSpecification>(_parent)->_node->convertWorldToLocalOrientation(q);
	_node->setOrientation(q);
	_node->_update(true,true);
}
Beispiel #5
0
Ogre::Quaternion RoomSurface::surfaceOrientationForNormal(Ogre::Vector3 normal) {
  Ogre::Real pi_by_two = Ogre::Math::PI/2.0;
  Ogre::Matrix3 mat;

  if (normal == Ogre::Vector3::UNIT_Y) {
    mat.FromEulerAnglesXYZ(Ogre::Radian(0), Ogre::Radian(0), Ogre::Radian(0));
  } else if (normal == Ogre::Vector3::UNIT_X) {
    mat.FromEulerAnglesXYZ(Ogre::Radian(pi_by_two), Ogre::Radian(0), Ogre::Radian(-pi_by_two));
  } else if (normal == -Ogre::Vector3::UNIT_X) {
    mat.FromEulerAnglesXYZ(Ogre::Radian(pi_by_two), Ogre::Radian(0), Ogre::Radian(pi_by_two));
  } else if (normal == Ogre::Vector3::UNIT_Z) {
    mat.FromEulerAnglesXYZ(Ogre::Radian(pi_by_two), Ogre::Radian(0), Ogre::Radian(0));
  } else if (normal == -Ogre::Vector3::UNIT_Z) {
    // the last component should ideally be  Ogre::Radian(2*pi_by_two), however the corresponding
    // physics constraint has a problem with that.
    mat.FromEulerAnglesXYZ(Ogre::Radian(pi_by_two), Ogre::Radian(2*pi_by_two), Ogre::Radian(0));
  }
  return Ogre::Quaternion(mat);
}
PhysicsRagDoll::RagBone::RagBone(PhysicsRagDoll* creator, OgreNewt::World* world, PhysicsRagDoll::RagBone* parent, Ogre::Bone* ogreBone, Ogre::MeshPtr mesh,
						  Ogre::Vector3 dir, PhysicsRagDoll::RagBone::BoneShape shape, Ogre::Vector3 size, Ogre::Real mass, Actor* parentActor)
{
	mDoll = creator;
	mParent = parent;
	mOgreBone = ogreBone;

	OgreNewt::ConvexCollisionPtr col;

	// in the case of the cylindrical primitives, they need to be rotated to align the main axis with the direction vector.
	Ogre::Quaternion orient = Ogre::Quaternion::IDENTITY;
	Ogre::Vector3 pos = Ogre::Vector3::ZERO;
	Ogre::Matrix3 rot;

	if (dir == Ogre::Vector3::UNIT_Y)
	{
		rot.FromEulerAnglesXYZ(Ogre::Degree(0), Ogre::Degree(0), Ogre::Degree(90));
		orient.FromRotationMatrix(rot);
	}

	if (dir == Ogre::Vector3::UNIT_Z)
	{
		rot.FromEulerAnglesXYZ(Ogre::Degree(0), Ogre::Degree(90), Ogre::Degree(0));
		orient.FromRotationMatrix(rot);
	}


	// make the rigid body.
	switch (shape)
	{
	case PhysicsRagDoll::RagBone::BS_BOX:
		col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box(world, size, 0));
		break;

	case PhysicsRagDoll::RagBone::BS_CAPSULE:
		col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Capsule(world, size.y, size.x, 0, orient, pos));
		break;

	case PhysicsRagDoll::RagBone::BS_CONE:
		col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Cone(world, size.y, size.x, 0, orient, pos));
		break;

	case PhysicsRagDoll::RagBone::BS_CYLINDER:
		col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Cylinder(world, size.y, size.x, 0, orient, pos));
		break;

	case PhysicsRagDoll::RagBone::BS_ELLIPSOID:
		col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Ellipsoid(world, size, 0));
		break;

	case PhysicsRagDoll::RagBone::BS_CONVEXHULL:
		col = _makeConvexHull(world, mesh, size.x);
		break;

	default:
		col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::Box(world, size, 0));
		break;
	}

    if (col)
    {
        if (col->getNewtonCollision() == NULL)
        {
            col.reset();
        }
    }

    if (!col)
    {
        LOG_WARNING(Logger::CORE, " error creating collision for '" + ogreBone->getName() + "', still continuing.");
        mBody = NULL;
    }
    else
    {
    	mBody = new OgreNewt::Body(world, col);
        mBody->setUserData(Ogre::Any(parentActor));
    	mBody->setStandardForceCallback();
        const OgreNewt::MaterialID* ragdollMat = PhysicsManager::getSingleton().createMaterialID("default");
        mBody->setMaterialGroupID(ragdollMat);

	    Ogre::Vector3 inertia;
    	Ogre::Vector3 com;
    	col->calculateInertialMatrix(inertia, com);
	
	    mBody->setMassMatrix(mass, inertia * mass);
    	mBody->setCenterOfMass(com);

	    mBody->setCustomTransformCallback(PhysicsRagDoll::_placementCallback);


    	mOgreBone->setManuallyControlled(true);
    }
}