forked from teamnwah/openmw-tes3coop
Remove BtOgre
parent
1943110170
commit
92cbc13964
File diff suppressed because it is too large
Load Diff
@ -1,284 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: BtOgreExtras.h
|
||||
*
|
||||
* Description: Contains the Ogre Mesh to Bullet Shape converters.
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 27/12/2008 01:45:56 PM
|
||||
*
|
||||
* Author: Nikhilesh (nikki)
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
|
||||
#ifndef BtOgreShapes_H_
|
||||
#define BtOgreShapes_H_
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "OgreSimpleRenderable.h"
|
||||
#include "OgreCamera.h"
|
||||
#include "OgreHardwareBufferManager.h"
|
||||
#include "OgreMaterialManager.h"
|
||||
#include "OgreTechnique.h"
|
||||
#include "OgrePass.h"
|
||||
|
||||
#include "OgreLogManager.h"
|
||||
|
||||
namespace BtOgre
|
||||
{
|
||||
|
||||
typedef std::vector<Ogre::Vector3> Vector3Array;
|
||||
|
||||
//Converts from and to Bullet and Ogre stuff. Pretty self-explanatory.
|
||||
class Convert
|
||||
{
|
||||
public:
|
||||
Convert() {};
|
||||
~Convert() {};
|
||||
|
||||
static btQuaternion toBullet(const Ogre::Quaternion &q)
|
||||
{
|
||||
return btQuaternion(q.x, q.y, q.z, q.w);
|
||||
}
|
||||
static btVector3 toBullet(const Ogre::Vector3 &v)
|
||||
{
|
||||
return btVector3(v.x, v.y, v.z);
|
||||
}
|
||||
|
||||
static Ogre::Quaternion toOgre(const btQuaternion &q)
|
||||
{
|
||||
return Ogre::Quaternion(q.w(), q.x(), q.y(), q.z());
|
||||
}
|
||||
static Ogre::Vector3 toOgre(const btVector3 &v)
|
||||
{
|
||||
return Ogre::Vector3(v.x(), v.y(), v.z());
|
||||
}
|
||||
};
|
||||
|
||||
//From here on its debug-drawing stuff. ------------------------------------------------------------------
|
||||
|
||||
class DynamicRenderable : public Ogre::SimpleRenderable
|
||||
{
|
||||
public:
|
||||
/// Constructor
|
||||
DynamicRenderable();
|
||||
/// Virtual destructor
|
||||
virtual ~DynamicRenderable();
|
||||
|
||||
/** Initializes the dynamic renderable.
|
||||
@remarks
|
||||
This function should only be called once. It initializes the
|
||||
render operation, and calls the abstract function
|
||||
createVertexDeclaration().
|
||||
@param operationType The type of render operation to perform.
|
||||
@param useIndices Specifies whether to use indices to determine the
|
||||
vertices to use as input. */
|
||||
void initialize(Ogre::RenderOperation::OperationType operationType,
|
||||
bool useIndices);
|
||||
|
||||
/// Implementation of Ogre::SimpleRenderable
|
||||
virtual Ogre::Real getBoundingRadius(void) const;
|
||||
/// Implementation of Ogre::SimpleRenderable
|
||||
virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera* cam) const;
|
||||
|
||||
protected:
|
||||
/// Maximum capacity of the currently allocated vertex buffer.
|
||||
size_t mVertexBufferCapacity;
|
||||
/// Maximum capacity of the currently allocated index buffer.
|
||||
size_t mIndexBufferCapacity;
|
||||
|
||||
/** Creates the vertex declaration.
|
||||
@remarks
|
||||
Override and set mRenderOp.vertexData->vertexDeclaration here.
|
||||
mRenderOp.vertexData will be created for you before this method
|
||||
is called. */
|
||||
virtual void createVertexDeclaration() = 0;
|
||||
|
||||
/** Prepares the hardware buffers for the requested vertex and index counts.
|
||||
@remarks
|
||||
This function must be called before locking the buffers in
|
||||
fillHardwareBuffers(). It guarantees that the hardware buffers
|
||||
are large enough to hold at least the requested number of
|
||||
vertices and indices (if using indices). The buffers are
|
||||
possibly reallocated to achieve this.
|
||||
@par
|
||||
The vertex and index count in the render operation are set to
|
||||
the values of vertexCount and indexCount respectively.
|
||||
@param vertexCount The number of vertices the buffer must hold.
|
||||
|
||||
@param indexCount The number of indices the buffer must hold. This
|
||||
parameter is ignored if not using indices. */
|
||||
void prepareHardwareBuffers(size_t vertexCount, size_t indexCount);
|
||||
|
||||
/** Fills the hardware vertex and index buffers with data.
|
||||
@remarks
|
||||
This function must call prepareHardwareBuffers() before locking
|
||||
the buffers to ensure the they are large enough for the data to
|
||||
be written. Afterwards the vertex and index buffers (if using
|
||||
indices) can be locked, and data can be written to them. */
|
||||
virtual void fillHardwareBuffers() = 0;
|
||||
};
|
||||
|
||||
class DynamicLines : public DynamicRenderable
|
||||
{
|
||||
typedef Ogre::Vector3 Vector3;
|
||||
typedef Ogre::Quaternion Quaternion;
|
||||
typedef Ogre::Camera Camera;
|
||||
typedef Ogre::Real Real;
|
||||
typedef Ogre::RenderOperation::OperationType OperationType;
|
||||
|
||||
public:
|
||||
/// Constructor - see setOperationType() for description of argument.
|
||||
DynamicLines(OperationType opType=Ogre::RenderOperation::OT_LINE_STRIP);
|
||||
virtual ~DynamicLines();
|
||||
|
||||
/// Add a point to the point list
|
||||
void addPoint(const Ogre::Vector3 &p);
|
||||
/// Add a point to the point list
|
||||
void addPoint(Real x, Real y, Real z);
|
||||
|
||||
/// Change the location of an existing point in the point list
|
||||
void setPoint(unsigned short index, const Vector3 &value);
|
||||
|
||||
/// Return the location of an existing point in the point list
|
||||
const Vector3& getPoint(unsigned short index) const;
|
||||
|
||||
/// Return the total number of points in the point list
|
||||
unsigned short getNumPoints(void) const;
|
||||
|
||||
/// Remove all points from the point list
|
||||
void clear();
|
||||
|
||||
/// Call this to update the hardware buffer after making changes.
|
||||
void update();
|
||||
|
||||
/** Set the type of operation to draw with.
|
||||
* @param opType Can be one of
|
||||
* - RenderOperation::OT_LINE_STRIP
|
||||
* - RenderOperation::OT_LINE_LIST
|
||||
* - RenderOperation::OT_POINT_LIST
|
||||
* - RenderOperation::OT_TRIANGLE_LIST
|
||||
* - RenderOperation::OT_TRIANGLE_STRIP
|
||||
* - RenderOperation::OT_TRIANGLE_FAN
|
||||
* The default is OT_LINE_STRIP.
|
||||
*/
|
||||
void setOperationType(OperationType opType);
|
||||
OperationType getOperationType() const;
|
||||
|
||||
protected:
|
||||
/// Implementation DynamicRenderable, creates a simple vertex-only decl
|
||||
virtual void createVertexDeclaration();
|
||||
/// Implementation DynamicRenderable, pushes point list out to hardware memory
|
||||
virtual void fillHardwareBuffers();
|
||||
|
||||
private:
|
||||
std::vector<Vector3> mPoints;
|
||||
bool mDirty;
|
||||
};
|
||||
|
||||
class DebugDrawer : public btIDebugDraw
|
||||
{
|
||||
protected:
|
||||
Ogre::SceneNode *mNode;
|
||||
btDynamicsWorld *mWorld;
|
||||
DynamicLines *mLineDrawer;
|
||||
bool mDebugOn;
|
||||
|
||||
public:
|
||||
|
||||
DebugDrawer(Ogre::SceneNode *node, btDynamicsWorld *world)
|
||||
: mNode(node),
|
||||
mWorld(world),
|
||||
mDebugOn(true)
|
||||
{
|
||||
mLineDrawer = new DynamicLines(Ogre::RenderOperation::OT_LINE_LIST);
|
||||
mNode->attachObject(mLineDrawer);
|
||||
|
||||
if (!Ogre::ResourceGroupManager::getSingleton().resourceGroupExists("BtOgre"))
|
||||
Ogre::ResourceGroupManager::getSingleton().createResourceGroup("BtOgre");
|
||||
if (!Ogre::MaterialManager::getSingleton().resourceExists("BtOgre/DebugLines"))
|
||||
{
|
||||
Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("BtOgre/DebugLines", "BtOgre");
|
||||
mat->setReceiveShadows(false);
|
||||
mat->setSelfIllumination(1,1,1);
|
||||
}
|
||||
|
||||
mLineDrawer->setMaterial("BtOgre/DebugLines");
|
||||
|
||||
//mLineDrawer->setVisibilityFlags (1024);
|
||||
}
|
||||
|
||||
~DebugDrawer()
|
||||
{
|
||||
if (Ogre::MaterialManager::getSingleton().resourceExists("BtOgre/DebugLines"))
|
||||
Ogre::MaterialManager::getSingleton().remove("BtOgre/DebugLines");
|
||||
if (Ogre::ResourceGroupManager::getSingleton().resourceGroupExists("BtOgre"))
|
||||
Ogre::ResourceGroupManager::getSingleton().destroyResourceGroup("BtOgre");
|
||||
delete mLineDrawer;
|
||||
}
|
||||
|
||||
void step()
|
||||
{
|
||||
if (mDebugOn)
|
||||
{
|
||||
mWorld->debugDrawWorld();
|
||||
mLineDrawer->update();
|
||||
mNode->needUpdate();
|
||||
mLineDrawer->clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
mLineDrawer->clear();
|
||||
mLineDrawer->update();
|
||||
mNode->needUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
|
||||
{
|
||||
mLineDrawer->addPoint(Convert::toOgre(from));
|
||||
mLineDrawer->addPoint(Convert::toOgre(to));
|
||||
}
|
||||
|
||||
void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color)
|
||||
{
|
||||
mLineDrawer->addPoint(Convert::toOgre(PointOnB));
|
||||
mLineDrawer->addPoint(Convert::toOgre(PointOnB) + (Convert::toOgre(normalOnB) * distance * 20));
|
||||
}
|
||||
|
||||
void reportErrorWarning(const char* warningString)
|
||||
{
|
||||
Ogre::LogManager::getSingleton().logMessage(warningString);
|
||||
}
|
||||
|
||||
void draw3dText(const btVector3& location,const char* textString)
|
||||
{
|
||||
}
|
||||
|
||||
//0 for off, anything else for on.
|
||||
void setDebugMode(int isOn)
|
||||
{
|
||||
mDebugOn = (isOn == 0) ? false : true;
|
||||
|
||||
if (!mDebugOn)
|
||||
mLineDrawer->clear();
|
||||
}
|
||||
|
||||
//0 for off, anything else for on.
|
||||
int getDebugMode() const
|
||||
{
|
||||
return mDebugOn;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,144 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: BtOgreGP.h
|
||||
*
|
||||
* Description: The part of BtOgre that handles information transfer from Ogre to
|
||||
* Bullet (like mesh data for making trimeshes).
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 27/12/2008 03:29:56 AM
|
||||
*
|
||||
* Author: Nikhilesh (nikki)
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
|
||||
#ifndef BtOgrePG_H_
|
||||
#define BtOgrePG_H_
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "BtOgreExtras.h"
|
||||
|
||||
#include <OgreMatrix4.h>
|
||||
#include <OgreMesh.h>
|
||||
#include <OgreVector3.h>
|
||||
|
||||
namespace BtOgre {
|
||||
|
||||
typedef std::map<unsigned char, Vector3Array*> BoneIndex;
|
||||
|
||||
class VertexIndexToShape
|
||||
{
|
||||
public:
|
||||
VertexIndexToShape(const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
|
||||
~VertexIndexToShape();
|
||||
|
||||
Ogre::Real getRadius();
|
||||
Ogre::Vector3 getSize();
|
||||
|
||||
|
||||
btSphereShape* createSphere();
|
||||
btBoxShape* createBox();
|
||||
btBvhTriangleMeshShape* createTrimesh();
|
||||
btCylinderShape* createCylinder();
|
||||
btConvexHullShape* createConvex();
|
||||
|
||||
const Ogre::Vector3* getVertices();
|
||||
unsigned int getVertexCount();
|
||||
const unsigned int* getIndices();
|
||||
unsigned int getIndexCount();
|
||||
|
||||
protected:
|
||||
|
||||
void addStaticVertexData(const Ogre::VertexData *vertex_data);
|
||||
|
||||
void addAnimatedVertexData(const Ogre::VertexData *vertex_data,
|
||||
const Ogre::VertexData *blended_data,
|
||||
const Ogre::Mesh::IndexMap *indexMap);
|
||||
|
||||
void addIndexData(Ogre::IndexData *data, const unsigned int offset = 0);
|
||||
|
||||
|
||||
protected:
|
||||
Ogre::Vector3* mVertexBuffer;
|
||||
unsigned int* mIndexBuffer;
|
||||
unsigned int mVertexCount;
|
||||
unsigned int mIndexCount;
|
||||
|
||||
Ogre::Matrix4 mTransform;
|
||||
|
||||
Ogre::Real mBoundRadius;
|
||||
Ogre::Vector3 mBounds;
|
||||
|
||||
BoneIndex *mBoneIndex;
|
||||
|
||||
Ogre::Vector3 mScale;
|
||||
};
|
||||
|
||||
//For static (non-animated) meshes.
|
||||
class StaticMeshToShapeConverter : public VertexIndexToShape
|
||||
{
|
||||
public:
|
||||
|
||||
StaticMeshToShapeConverter(Ogre::Renderable *rend, const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
|
||||
StaticMeshToShapeConverter(Ogre::Entity *entity, const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
|
||||
StaticMeshToShapeConverter();
|
||||
|
||||
~StaticMeshToShapeConverter();
|
||||
|
||||
void addEntity(Ogre::Entity *entity,const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
|
||||
|
||||
void addMesh(const Ogre::MeshPtr &mesh, const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
Ogre::Entity* mEntity;
|
||||
Ogre::SceneNode* mNode;
|
||||
};
|
||||
|
||||
//For animated meshes.
|
||||
class AnimatedMeshToShapeConverter : public VertexIndexToShape
|
||||
{
|
||||
public:
|
||||
|
||||
AnimatedMeshToShapeConverter(Ogre::Entity *entity, const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
|
||||
AnimatedMeshToShapeConverter();
|
||||
~AnimatedMeshToShapeConverter();
|
||||
|
||||
void addEntity(Ogre::Entity *entity,const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
|
||||
void addMesh(const Ogre::MeshPtr &mesh, const Ogre::Matrix4 &transform);
|
||||
|
||||
btBoxShape* createAlignedBox(unsigned char bone,
|
||||
const Ogre::Vector3 &bonePosition,
|
||||
const Ogre::Quaternion &boneOrientation);
|
||||
|
||||
btBoxShape* createOrientedBox(unsigned char bone,
|
||||
const Ogre::Vector3 &bonePosition,
|
||||
const Ogre::Quaternion &boneOrientation);
|
||||
|
||||
protected:
|
||||
|
||||
bool getBoneVertices(unsigned char bone,
|
||||
unsigned int &vertex_count,
|
||||
Ogre::Vector3* &vertices,
|
||||
const Ogre::Vector3 &bonePosition);
|
||||
|
||||
bool getOrientedBox(unsigned char bone,
|
||||
const Ogre::Vector3 &bonePosition,
|
||||
const Ogre::Quaternion &boneOrientation,
|
||||
Ogre::Vector3 &extents,
|
||||
Ogre::Vector3 *axis,
|
||||
Ogre::Vector3 ¢er);
|
||||
|
||||
Ogre::Entity* mEntity;
|
||||
Ogre::SceneNode* mNode;
|
||||
|
||||
Ogre::Vector3 *mTransformedVerticesTemp;
|
||||
size_t mTransformedVerticesTempSize;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* =====================================================================================
|
||||
*
|
||||
* Filename: BtOgrePG.h
|
||||
*
|
||||
* Description: The part of BtOgre that handles information transfer from Bullet to
|
||||
* Ogre (like updating graphics object positions).
|
||||
*
|
||||
* Version: 1.0
|
||||
* Created: 27/12/2008 03:40:56 AM
|
||||
*
|
||||
* Author: Nikhilesh (nikki)
|
||||
*
|
||||
* =====================================================================================
|
||||
*/
|
||||
|
||||
#ifndef BtOgreGP_H_
|
||||
#define BtOgreGP_H_
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "OgreSceneNode.h"
|
||||
#include "BtOgreExtras.h"
|
||||
|
||||
namespace BtOgre {
|
||||
|
||||
//A MotionState is Bullet's way of informing you about updates to an object.
|
||||
//Pass this MotionState to a btRigidBody to have your SceneNode updated automaticaly.
|
||||
class RigidBodyState : public btMotionState
|
||||
{
|
||||
protected:
|
||||
btTransform mTransform;
|
||||
btTransform mCenterOfMassOffset;
|
||||
|
||||
Ogre::SceneNode *mNode;
|
||||
|
||||
public:
|
||||
RigidBodyState(Ogre::SceneNode *node, const btTransform &transform, const btTransform &offset = btTransform::getIdentity())
|
||||
: mTransform(transform),
|
||||
mCenterOfMassOffset(offset),
|
||||
mNode(node)
|
||||
{
|
||||
}
|
||||
|
||||
RigidBodyState(Ogre::SceneNode *node)
|
||||
: mTransform(((node != NULL) ? BtOgre::Convert::toBullet(node->getOrientation()) : btQuaternion(0,0,0,1)),
|
||||
((node != NULL) ? BtOgre::Convert::toBullet(node->getPosition()) : btVector3(0,0,0))),
|
||||
mCenterOfMassOffset(btTransform::getIdentity()),
|
||||
mNode(node)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void getWorldTransform(btTransform &ret) const
|
||||
{
|
||||
ret = mCenterOfMassOffset.inverse() * mTransform;
|
||||
}
|
||||
|
||||
virtual void setWorldTransform(const btTransform &in)
|
||||
{
|
||||
if (mNode == NULL)
|
||||
return;
|
||||
|
||||
mTransform = in;
|
||||
btTransform transform = in * mCenterOfMassOffset;
|
||||
|
||||
btQuaternion rot = transform.getRotation();
|
||||
btVector3 pos = transform.getOrigin();
|
||||
mNode->setOrientation(rot.w(), rot.x(), rot.y(), rot.z());
|
||||
mNode->setPosition(pos.x(), pos.y(), pos.z());
|
||||
}
|
||||
|
||||
void setNode(Ogre::SceneNode *node)
|
||||
{
|
||||
mNode = node;
|
||||
}
|
||||
};
|
||||
|
||||
//Softbody-Ogre connection goes here!
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue