teienlib 0.0.1-x86-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +31 -0
- data/ext/teienlib/extconf.rb +35 -0
- data/ext/teienlib/interface/AnimationBlender.i +8 -0
- data/ext/teienlib/interface/CollisionChecker.i +22 -0
- data/ext/teienlib/interface/DebugDrawer.i +8 -0
- data/ext/teienlib/interface/MeshStrider.i +8 -0
- data/ext/teienlib/interface/Rakefile +27 -0
- data/ext/teienlib/interface/SoftBody.i +9 -0
- data/ext/teienlib/interface/teienlib.i +36 -0
- data/ext/teienlib/src/AnimationBlender.cc +141 -0
- data/ext/teienlib/src/AnimationBlender.h +41 -0
- data/ext/teienlib/src/Collision.cc +797 -0
- data/ext/teienlib/src/Collision.h +130 -0
- data/ext/teienlib/src/CollisionChecker.cc +67 -0
- data/ext/teienlib/src/CollisionChecker.h +33 -0
- data/ext/teienlib/src/DebugDrawer.h +66 -0
- data/ext/teienlib/src/MeshStrider.cc +112 -0
- data/ext/teienlib/src/MeshStrider.h +48 -0
- data/ext/teienlib/src/Shape.cc +9 -0
- data/ext/teienlib/src/Shape.h +186 -0
- data/ext/teienlib/src/SimpleCollisionLibrary.h +7 -0
- data/ext/teienlib/src/SoftBody.cc +148 -0
- data/ext/teienlib/src/SoftBody.h +14 -0
- data/ext/teienlib/src/Vector3D.h +92 -0
- data/lib/Teienlib.so +0 -0
- data/lib/teienlib/version.rb +3 -0
- data/lib/teienlib.rb +5 -0
- data/teienlib.gemspec +33 -0
- metadata +98 -0
@@ -0,0 +1,130 @@
|
|
1
|
+
#ifndef COLLISION_H
|
2
|
+
#define COLLISION_H
|
3
|
+
|
4
|
+
#include <map>
|
5
|
+
#include <deque>
|
6
|
+
#include <utility>
|
7
|
+
#include <string>
|
8
|
+
|
9
|
+
class Entity;
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Collision library:
|
13
|
+
*
|
14
|
+
* This code is based on an excelent book, called Real-Time Collision Detection.
|
15
|
+
*/
|
16
|
+
|
17
|
+
|
18
|
+
#include "Shape.h"
|
19
|
+
|
20
|
+
/// ��ư��Ʊ�Τξ���Ƚ�ꡣ�ߤޤäƤƤ⤤����
|
21
|
+
/**
|
22
|
+
* �����˽٤������ȤǤϤʤ������Ȥ�������ޤ�ޤǤ����˵�����
|
23
|
+
*
|
24
|
+
* ���Υ��饹�η�ޤ��:
|
25
|
+
* t�Ͼ�� 0 <= t <= 1
|
26
|
+
* ���äơ�������ֶ�� dt �Ǥθ������
|
27
|
+
* V��Ĵ�����롣V = Vorg * dt
|
28
|
+
*
|
29
|
+
* Moving intersect��vel�ϡ�
|
30
|
+
* shapeB��®�٤�0�ˤ��롣�Ĥޤ�
|
31
|
+
* Vel = A.vel - B.vel
|
32
|
+
* V��Ĵ����
|
33
|
+
*/
|
34
|
+
|
35
|
+
namespace scl{
|
36
|
+
|
37
|
+
class Collision
|
38
|
+
{
|
39
|
+
public:
|
40
|
+
Collision();
|
41
|
+
virtual ~Collision();
|
42
|
+
|
43
|
+
void setDebug(bool aBool){ debug = aBool; }
|
44
|
+
|
45
|
+
/// Moving intersetct wrapper
|
46
|
+
/**
|
47
|
+
* 1. ®�٤κ�ʬ��ȤꡢshapeB��ߤᡢshapeA������®�٤Τߤˤ��롣
|
48
|
+
* 2. ®�٤����Ĥ�Ʊ̾�ؿ���Ƥ�
|
49
|
+
*/
|
50
|
+
bool intersectMovingShapes(Shape* shapeA, Vector3D<float> velA,
|
51
|
+
Shape* shapeB, Vector3D<float> velB,
|
52
|
+
float delta, float *t);
|
53
|
+
/// Moving intersect
|
54
|
+
/**
|
55
|
+
* 1. ������Ƚ�̤��롣
|
56
|
+
* 2. �����ϰϤ�1�ˤ��뤿��ˡ�®�٤��ѹ�����(delta�ܤ���)��
|
57
|
+
* 3. �����˹�碌��ɾ���ؿ���Ƥ֡�
|
58
|
+
*/
|
59
|
+
bool intersectMovingShapes(Shape* shapeA, Vector3D<float> vel,
|
60
|
+
Shape* shapeB,
|
61
|
+
float delta, float *t);
|
62
|
+
|
63
|
+
//
|
64
|
+
// Basic collision function
|
65
|
+
//
|
66
|
+
|
67
|
+
// Test
|
68
|
+
bool testAABBAABB(AABB boxA, AABB boxB);
|
69
|
+
|
70
|
+
// Closest Point
|
71
|
+
void closestPtSegment(Segment sg, Vector3D<float> aPos, Vector3D<float> *aXPos);
|
72
|
+
float closestPtSegmentSegment(Segment sg1, Segment sg2,
|
73
|
+
float *s, float *t,
|
74
|
+
Vector3D<float> *c1, Vector3D<float> *c2);
|
75
|
+
// Intersect
|
76
|
+
/**
|
77
|
+
* Ray intersetct
|
78
|
+
* ray = p + dir * t
|
79
|
+
* colP = dir * t
|
80
|
+
*/
|
81
|
+
bool intersectRayPlane(Vector3D<float> p, Vector3D<float> dir, Plane pl,
|
82
|
+
float *t, Vector3D<float> *colP);
|
83
|
+
bool intersectRayAABB(Vector3D<float> p, Vector3D<float> dir, AABB box,
|
84
|
+
float *dist, Vector3D<float> *colP);
|
85
|
+
bool intersectRaySphere(Vector3D<float> p, Vector3D<float> dir, Sphere sp,
|
86
|
+
float *t, Vector3D<float> *colP);
|
87
|
+
|
88
|
+
/**
|
89
|
+
* 1. 0 <= *t <= 1
|
90
|
+
* 2. ���ͤޤǤε�Υ�� seg.len() * (*t)
|
91
|
+
*/
|
92
|
+
bool intersectSegmentSphere(Segment seg, Sphere sp, float *t);
|
93
|
+
bool intersectSegmentCapsule(Segment sg, Capsule cap, float *t);
|
94
|
+
|
95
|
+
private:
|
96
|
+
typedef bool (Collision::*ColFuncPtr)(Shape*, Vector3D<float>, Shape*, float *);
|
97
|
+
typedef std::map<pair<std::string, std::string>, ColFuncPtr> ColMap;
|
98
|
+
|
99
|
+
pair<std::string, std::string> makeStringPair(const char *s1, const char *s2);
|
100
|
+
|
101
|
+
ColMap* initCollisionMap();
|
102
|
+
ColFuncPtr lookup(const std::string & classA, const std::string & classB);
|
103
|
+
|
104
|
+
// Shape���������顢�������ɲ�
|
105
|
+
|
106
|
+
bool intersectMovingSphereSphere(Shape* sphereA, Vector3D<float> vel, Shape* sphereB, float *t);
|
107
|
+
bool intersectMovingSpherePlane(Shape* sphere, Vector3D<float> vel, Shape* plane, float *t);
|
108
|
+
bool intersectMovingSphereAABB(Shape* sphere, Vector3D<float> vel, Shape* aabb, float *t);
|
109
|
+
bool intersectMovingAABBAABB(Shape* aabbA, Vector3D<float> vel, Shape* aabbB, float *t);
|
110
|
+
bool intersectMovingAABBPlane(Shape* aabb, Vector3D<float> vel, Shape* plane, float *t);
|
111
|
+
bool intersectMovingPlanePlane(Shape* planeA, Vector3D<float> vel, Shape* planeB, float *t);
|
112
|
+
|
113
|
+
bool intersectMovingPlaneSphere(Shape* pl, Vector3D<float> vel, Shape* sp, float *t)
|
114
|
+
{
|
115
|
+
return intersectMovingSpherePlane(sp, -vel, pl, t);
|
116
|
+
}
|
117
|
+
bool intersectMovingAABBSphere(Shape* box, Vector3D<float> vel, Shape* sp, float *t)
|
118
|
+
{
|
119
|
+
return intersectMovingSphereAABB(sp, -vel, box, t);
|
120
|
+
}
|
121
|
+
bool intersectMovingPlaneAABB(Shape* pl, Vector3D<float> vel, Shape* box, float *t)
|
122
|
+
{
|
123
|
+
return intersectMovingAABBPlane(box, -vel, pl, t);
|
124
|
+
}
|
125
|
+
|
126
|
+
bool debug;
|
127
|
+
};
|
128
|
+
|
129
|
+
}
|
130
|
+
#endif
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#include "CollisionChecker.h"
|
2
|
+
|
3
|
+
bool
|
4
|
+
CollisionChecker::intersectMovingShapes(btCollisionShape* shapeA,
|
5
|
+
btVector3 posA,
|
6
|
+
btVector3 velA,
|
7
|
+
btCollisionShape* shapeB,
|
8
|
+
btVector3 posB,
|
9
|
+
btVector3 velB,
|
10
|
+
float delta)
|
11
|
+
{
|
12
|
+
float t;
|
13
|
+
return col.intersectMovingShapes(convertShape(shapeA, posA),
|
14
|
+
convertVector(velA),
|
15
|
+
convertShape(shapeB, posB),
|
16
|
+
convertVector(velB),
|
17
|
+
delta, &t);
|
18
|
+
}
|
19
|
+
|
20
|
+
|
21
|
+
bool
|
22
|
+
CollisionChecker::intersectRayAABB(btVector3 p, btVector3 dir,
|
23
|
+
btBoxShape* box, btVector3 pos,
|
24
|
+
btVector3* colP)
|
25
|
+
{
|
26
|
+
float t;
|
27
|
+
sul::Vector3D<float> xPt;
|
28
|
+
bool bl = col.intersectRayAABB(convertVector(p),
|
29
|
+
convertVector(dir),
|
30
|
+
*(scl::AABB*)convertShape(box, pos),
|
31
|
+
&t, &xPt);
|
32
|
+
colP->setValue(xPt.x, xPt.y, xPt.z);
|
33
|
+
return bl;
|
34
|
+
}
|
35
|
+
|
36
|
+
void
|
37
|
+
CollisionChecker::closestPtSegment(btVector3 segA, btVector3 segB,
|
38
|
+
btVector3 pos, btVector3* colP)
|
39
|
+
{
|
40
|
+
sul::Vector3D<float> xPt;
|
41
|
+
col.closestPtSegment(scl::Segment(convertVector(segA), convertVector(segB)),
|
42
|
+
convertVector(pos), &xPt);
|
43
|
+
colP->setValue(xPt.x, xPt.y, xPt.z);
|
44
|
+
}
|
45
|
+
|
46
|
+
|
47
|
+
scl::Shape*
|
48
|
+
CollisionChecker::convertShape(btCollisionShape* btShape, btVector3 btPos)
|
49
|
+
{
|
50
|
+
if (btBoxShape* btBox = dynamic_cast<btBoxShape*>(btShape)) {
|
51
|
+
scl::AABB* shape = new scl::AABB();
|
52
|
+
shape->setPos(convertVector(btPos),
|
53
|
+
convertVector(btBox->getHalfExtentsWithMargin()));
|
54
|
+
return shape;
|
55
|
+
}
|
56
|
+
else {
|
57
|
+
std::cerr << __PRETTY_FUNCTION__ << ": This shape is not supported." << std::endl;
|
58
|
+
return NULL;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
|
63
|
+
sul::Vector3D<float>
|
64
|
+
CollisionChecker::convertVector(btVector3 btVec)
|
65
|
+
{
|
66
|
+
return sul::Vector3D<float>(btVec.x(), btVec.y(), btVec.z());
|
67
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#ifndef __CollisionChecker_h__
|
2
|
+
#define __CollisionChecker_h__
|
3
|
+
|
4
|
+
#include "Collision.h"
|
5
|
+
#include <btBulletCollisionCommon.h>
|
6
|
+
|
7
|
+
class CollisionChecker
|
8
|
+
{
|
9
|
+
public:
|
10
|
+
bool intersectMovingShapes(btCollisionShape* shapeA,
|
11
|
+
btVector3 posA,
|
12
|
+
btVector3 velA,
|
13
|
+
btCollisionShape* shapeB,
|
14
|
+
btVector3 posB,
|
15
|
+
btVector3 velB,
|
16
|
+
float delta);
|
17
|
+
|
18
|
+
|
19
|
+
bool intersectRayAABB(btVector3 p, btVector3 dir,
|
20
|
+
btBoxShape* box, btVector3 pos,
|
21
|
+
btVector3* colP);
|
22
|
+
|
23
|
+
void closestPtSegment(btVector3 segA, btVector3 segB,
|
24
|
+
btVector3 pos, btVector3* xPt);
|
25
|
+
|
26
|
+
scl::Shape* convertShape(btCollisionShape* btShape, btVector3 btPos);
|
27
|
+
sul::Vector3D<float> convertVector(btVector3 btVec);
|
28
|
+
|
29
|
+
private:
|
30
|
+
scl::Collision col;
|
31
|
+
};
|
32
|
+
|
33
|
+
#endif
|
@@ -0,0 +1,66 @@
|
|
1
|
+
/*
|
2
|
+
* The class is a snippet of http://www.ogre3d.org/tikiwiki/BulletDebugDrawer&structure=Cookbook.
|
3
|
+
*/
|
4
|
+
|
5
|
+
#ifndef DebugDrawer_h__
|
6
|
+
#define DebugDrawer_h__
|
7
|
+
|
8
|
+
//#include "../common.h"
|
9
|
+
|
10
|
+
#include <Ogre.h>
|
11
|
+
#include <btBulletDynamicsCommon.h>
|
12
|
+
|
13
|
+
class DebugDrawer: public btIDebugDraw, public Ogre::FrameListener{
|
14
|
+
public:
|
15
|
+
DebugDrawer( Ogre::SceneManager *scm );
|
16
|
+
~DebugDrawer ();
|
17
|
+
virtual void drawLine (const btVector3 &from, const btVector3 &to, const btVector3 &color);
|
18
|
+
virtual void drawTriangle (const btVector3 &v0, const btVector3 &v1, const btVector3 &v2,
|
19
|
+
const btVector3 &color, btScalar);
|
20
|
+
virtual void drawContactPoint (const btVector3 &PointOnB, const btVector3 &normalOnB,
|
21
|
+
btScalar distance, int lifeTime, const btVector3 &color);
|
22
|
+
virtual void reportErrorWarning (const char *warningString);
|
23
|
+
virtual void draw3dText (const btVector3 &location, const char *textString);
|
24
|
+
virtual void setDebugMode (int debugMode);
|
25
|
+
virtual int getDebugMode () const;
|
26
|
+
protected:
|
27
|
+
bool frameStarted(const Ogre::FrameEvent& evt);
|
28
|
+
void callBegin();
|
29
|
+
// bool frameRenderingQueued (const Ogre::FrameEvent &evt);
|
30
|
+
// bool frameEnded(const Ogre::FrameEvent& evt);
|
31
|
+
private:
|
32
|
+
struct ContactPoint{
|
33
|
+
Ogre::Vector3 from;
|
34
|
+
Ogre::Vector3 to;
|
35
|
+
Ogre::ColourValue color;
|
36
|
+
size_t dieTime;
|
37
|
+
};
|
38
|
+
DebugDrawModes mDebugModes;
|
39
|
+
Ogre::ManualObject *mLines;
|
40
|
+
Ogre::ManualObject *mTriangles;
|
41
|
+
std::vector< ContactPoint > *mContactPoints;
|
42
|
+
std::vector< ContactPoint > mContactPoints1;
|
43
|
+
std::vector< ContactPoint > mContactPoints2;
|
44
|
+
|
45
|
+
bool mRequestBegin;
|
46
|
+
};
|
47
|
+
|
48
|
+
inline btVector3 cvt(const Ogre::Vector3 &V){
|
49
|
+
return btVector3(V.x, V.y, V.z);
|
50
|
+
}
|
51
|
+
|
52
|
+
inline Ogre::Vector3 cvt(const btVector3&V){
|
53
|
+
return Ogre::Vector3(V.x(), V.y(), V.z());
|
54
|
+
}
|
55
|
+
|
56
|
+
inline btQuaternion cvt(const Ogre::Quaternion &Q)
|
57
|
+
{
|
58
|
+
return btQuaternion(Q.x, Q.y, Q.z, Q.w);
|
59
|
+
};
|
60
|
+
|
61
|
+
inline Ogre::Quaternion cvt(const btQuaternion &Q)
|
62
|
+
{
|
63
|
+
return Ogre::Quaternion(Q.w(), Q.x(), Q.y(), Q.z());
|
64
|
+
};
|
65
|
+
|
66
|
+
#endif // DebugDrawer_h__
|
@@ -0,0 +1,112 @@
|
|
1
|
+
#include "MeshStrider.h"
|
2
|
+
|
3
|
+
int MeshStrider::getNumSubParts() const
|
4
|
+
{
|
5
|
+
int ret = mMesh->getNumSubMeshes();
|
6
|
+
ASSERT( ret > 0 );
|
7
|
+
return ret;
|
8
|
+
}
|
9
|
+
|
10
|
+
void MeshStrider::getLockedReadOnlyVertexIndexBase(
|
11
|
+
const unsigned char **vertexbase,
|
12
|
+
int& numverts,
|
13
|
+
PHY_ScalarType& type,
|
14
|
+
int& stride,
|
15
|
+
const unsigned char **indexbase,
|
16
|
+
int & indexstride,
|
17
|
+
int& numfaces,
|
18
|
+
PHY_ScalarType& indicestype,
|
19
|
+
int subpart/*=0*/ ) const
|
20
|
+
{
|
21
|
+
Ogre::SubMesh* submesh = mMesh->getSubMesh(subpart);
|
22
|
+
Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mMesh->sharedVertexData : submesh->vertexData;
|
23
|
+
|
24
|
+
const Ogre::VertexElement* posElem =
|
25
|
+
vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
|
26
|
+
|
27
|
+
Ogre::HardwareVertexBufferSharedPtr vbuf =
|
28
|
+
vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());
|
29
|
+
|
30
|
+
*vertexbase = reinterpret_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
|
31
|
+
// There is _no_ baseVertexPointerToElement() which takes an Ogre::Real or a double
|
32
|
+
// as second argument. So make it float, to avoid trouble when Ogre::Real will
|
33
|
+
// be comiled/typedefed as double:
|
34
|
+
//Ogre::Real* pReal;
|
35
|
+
float* pReal;
|
36
|
+
posElem->baseVertexPointerToElement((void*) *vertexbase, &pReal);
|
37
|
+
*vertexbase = (unsigned char*) pReal;
|
38
|
+
|
39
|
+
stride = (int) vbuf->getVertexSize();
|
40
|
+
|
41
|
+
numverts = (int) vertex_data->vertexCount;
|
42
|
+
ASSERT( numverts );
|
43
|
+
|
44
|
+
type = PHY_FLOAT;
|
45
|
+
|
46
|
+
Ogre::IndexData* index_data = submesh->indexData;
|
47
|
+
Ogre::HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer;
|
48
|
+
|
49
|
+
if (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT){
|
50
|
+
indicestype = PHY_INTEGER;
|
51
|
+
}
|
52
|
+
else{
|
53
|
+
ASSERT(ibuf->getType() == Ogre::HardwareIndexBuffer::IT_16BIT);
|
54
|
+
indicestype = PHY_SHORT;
|
55
|
+
}
|
56
|
+
|
57
|
+
if ( submesh->operationType == Ogre::RenderOperation::OT_TRIANGLE_LIST ){
|
58
|
+
numfaces = (int) index_data->indexCount / 3;
|
59
|
+
indexstride = (int) ibuf->getIndexSize()*3;
|
60
|
+
}
|
61
|
+
else
|
62
|
+
if ( submesh->operationType == Ogre::RenderOperation::OT_TRIANGLE_STRIP ){
|
63
|
+
numfaces = (int) index_data->indexCount -2;
|
64
|
+
indexstride = (int) ibuf->getIndexSize();
|
65
|
+
}
|
66
|
+
else{
|
67
|
+
ASSERT( 0 ); // not supported
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
*indexbase = reinterpret_cast<unsigned char*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
|
73
|
+
}
|
74
|
+
|
75
|
+
void MeshStrider::getLockedVertexIndexBase( unsigned char **vertexbase, int& numverts,PHY_ScalarType& type, int& stride,unsigned char **indexbase,int & indexstride,int& numfaces,PHY_ScalarType& indicestype,int subpart/*=0*/ )
|
76
|
+
{
|
77
|
+
ASSERT( 0 );
|
78
|
+
}
|
79
|
+
|
80
|
+
void MeshStrider::unLockReadOnlyVertexBase( int subpart ) const
|
81
|
+
{
|
82
|
+
Ogre::SubMesh* submesh = mMesh->getSubMesh(subpart);
|
83
|
+
|
84
|
+
Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mMesh->sharedVertexData : submesh->vertexData;
|
85
|
+
|
86
|
+
const Ogre::VertexElement* posElem =
|
87
|
+
vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
|
88
|
+
|
89
|
+
Ogre::HardwareVertexBufferSharedPtr vbuf =
|
90
|
+
vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());
|
91
|
+
|
92
|
+
vbuf->unlock();
|
93
|
+
|
94
|
+
Ogre::IndexData* index_data = submesh->indexData;
|
95
|
+
Ogre::HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer;
|
96
|
+
ibuf->unlock();
|
97
|
+
}
|
98
|
+
|
99
|
+
void MeshStrider::unLockVertexBase( int subpart )
|
100
|
+
{
|
101
|
+
ASSERT( 0 );
|
102
|
+
}
|
103
|
+
|
104
|
+
void MeshStrider::preallocateVertices( int numverts )
|
105
|
+
{
|
106
|
+
ASSERT( 0 );
|
107
|
+
}
|
108
|
+
|
109
|
+
void MeshStrider::preallocateIndices( int numindices )
|
110
|
+
{
|
111
|
+
ASSERT( 0 );
|
112
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#ifndef _MESHSTRIDER_H
|
2
|
+
#define _MESHSTRIDER_H
|
3
|
+
|
4
|
+
#include "Ogre.h"
|
5
|
+
#include "btBulletCollisionCommon.h"
|
6
|
+
#include "btBulletDynamicsCommon.h"
|
7
|
+
|
8
|
+
#define ASSERT(a)
|
9
|
+
|
10
|
+
class MeshStrider : public btStridingMeshInterface
|
11
|
+
{
|
12
|
+
public:
|
13
|
+
MeshStrider( Ogre::Mesh * m = 0 ) : mMesh(m){}
|
14
|
+
|
15
|
+
void set( Ogre::Mesh * m ) { ASSERT(m); mMesh = m; }
|
16
|
+
// inherited interface
|
17
|
+
virtual int getNumSubParts() const;
|
18
|
+
|
19
|
+
virtual void getLockedVertexIndexBase(unsigned char **vertexbase,
|
20
|
+
int& numverts,
|
21
|
+
PHY_ScalarType& type,
|
22
|
+
int& stride,
|
23
|
+
unsigned char **indexbase,
|
24
|
+
int & indexstride,
|
25
|
+
int& numfaces,
|
26
|
+
PHY_ScalarType& indicestype,
|
27
|
+
int subpart=0);
|
28
|
+
virtual void getLockedReadOnlyVertexIndexBase(const unsigned char **vertexbase,
|
29
|
+
int& numverts,
|
30
|
+
PHY_ScalarType& type,
|
31
|
+
int& stride,
|
32
|
+
const unsigned char **indexbase,
|
33
|
+
int & indexstride,
|
34
|
+
int& numfaces,
|
35
|
+
PHY_ScalarType& indicestype,
|
36
|
+
int subpart=0) const;
|
37
|
+
|
38
|
+
virtual void unLockVertexBase(int subpart);
|
39
|
+
virtual void unLockReadOnlyVertexBase(int subpart) const;
|
40
|
+
|
41
|
+
virtual void preallocateVertices(int numverts);
|
42
|
+
virtual void preallocateIndices(int numindices);
|
43
|
+
|
44
|
+
private:
|
45
|
+
Ogre::Mesh * mMesh;
|
46
|
+
};
|
47
|
+
|
48
|
+
#endif
|
@@ -0,0 +1,186 @@
|
|
1
|
+
#ifndef SHAPE_H
|
2
|
+
#define SHAPE_H
|
3
|
+
|
4
|
+
#include "Vector3D.h"
|
5
|
+
|
6
|
+
using namespace sul;
|
7
|
+
|
8
|
+
namespace scl{
|
9
|
+
|
10
|
+
struct Shape
|
11
|
+
{
|
12
|
+
Shape();
|
13
|
+
virtual ~Shape(){}
|
14
|
+
virtual void setPos(Vector3D<float> aPos){ cerr << "Error: Shape::setPos()" << endl;}
|
15
|
+
|
16
|
+
virtual const char* getClassName() const = 0;
|
17
|
+
|
18
|
+
// aDir & localPos�ˤ����֤���ޤ�
|
19
|
+
//virtual void setPos(Vector3D<float> aPos, Vector3D<float> aDir){ cerr << "Error: Shape::setPos()" << endl;}
|
20
|
+
virtual void printInfo() const { cout << "struct: Shape" << endl; }
|
21
|
+
|
22
|
+
/// relative position to Entity
|
23
|
+
/**
|
24
|
+
* localPos�ϡ�Entity��pos(0, 0, 0), dir(0, -1, 0)�λ��ΰ��֤ˤ�������
|
25
|
+
* dir�˴ؤ��Ƥϸ���̤�б�
|
26
|
+
*/
|
27
|
+
Vector3D<float> localPos;
|
28
|
+
};
|
29
|
+
|
30
|
+
struct AABB : public Shape
|
31
|
+
{
|
32
|
+
AABB(){}
|
33
|
+
AABB(Vector3D<float> aMin, Vector3D<float> aMax) : min(aMin), max(aMax){}
|
34
|
+
~AABB(){}
|
35
|
+
Vector3D<float> getCenter() const
|
36
|
+
{
|
37
|
+
return (min + max) / 2;
|
38
|
+
}
|
39
|
+
Vector3D<float> getRadius() const
|
40
|
+
{
|
41
|
+
return (max - min) / 2;
|
42
|
+
}
|
43
|
+
|
44
|
+
void setPos(Vector3D<float> aCenter, Vector3D<float> aRad)
|
45
|
+
{
|
46
|
+
aCenter = aCenter + localPos;
|
47
|
+
min = aCenter - aRad;
|
48
|
+
max = aCenter + aRad;
|
49
|
+
}
|
50
|
+
void setPos(Vector3D<float> aCenter)
|
51
|
+
{
|
52
|
+
setPos(aCenter, getRadius());
|
53
|
+
}
|
54
|
+
void setRadius(Vector3D<float> aRad)
|
55
|
+
{
|
56
|
+
setPos(getCenter(), aRad);
|
57
|
+
}
|
58
|
+
|
59
|
+
const char* getClassName() const { return "AABB"; }
|
60
|
+
|
61
|
+
void printInfo() const
|
62
|
+
{
|
63
|
+
Vector3D<float> vect = getCenter();
|
64
|
+
cout << "** struct: AABB [" << this << "]" << endl;
|
65
|
+
cout << "center: (" << vect.x << ", " << vect.y << ", " << vect.z <<")" << endl;
|
66
|
+
vect = getRadius();
|
67
|
+
cout << "radius: (" << vect.x << ", " << vect.y << ", " << vect.z <<")" << endl;
|
68
|
+
}
|
69
|
+
|
70
|
+
Vector3D<float> min;
|
71
|
+
Vector3D<float> max;
|
72
|
+
};
|
73
|
+
|
74
|
+
struct Sphere : public Shape
|
75
|
+
{
|
76
|
+
Sphere(){};
|
77
|
+
~Sphere(){};
|
78
|
+
Sphere(Vector3D<float> aCen, float aRad)
|
79
|
+
{
|
80
|
+
c = aCen + localPos; r = aRad;
|
81
|
+
}
|
82
|
+
|
83
|
+
float getRadius() const { return r; }
|
84
|
+
Vector3D<float> getCenter() const { return c; }
|
85
|
+
|
86
|
+
void setPos(Vector3D<float> aCenter)
|
87
|
+
{
|
88
|
+
c = aCenter + localPos;
|
89
|
+
}
|
90
|
+
void setRadius(float aRad)
|
91
|
+
{
|
92
|
+
r = aRad;
|
93
|
+
}
|
94
|
+
void setPos(Vector3D<float> aCenter, float aRad)
|
95
|
+
{
|
96
|
+
setPos(aCenter);
|
97
|
+
setRadius(aRad);
|
98
|
+
}
|
99
|
+
|
100
|
+
const char* getClassName() const { return "Sphere"; }
|
101
|
+
|
102
|
+
void printInfo() const
|
103
|
+
{
|
104
|
+
Vector3D<float> vect = getCenter();
|
105
|
+
cout << "** struct: Sphere [" << this << "]" << endl;
|
106
|
+
cout << "center: (" << vect.x << ", " << vect.y << ", " << vect.z <<")" << endl;
|
107
|
+
cout << "radius: " << r << endl;
|
108
|
+
}
|
109
|
+
|
110
|
+
Vector3D<float> c; // center
|
111
|
+
float r;
|
112
|
+
};
|
113
|
+
|
114
|
+
/**
|
115
|
+
* n.dot(x) - d = 0;
|
116
|
+
* nx * x + ny * y + nz * z - d = 0;
|
117
|
+
*/
|
118
|
+
struct Plane : public Shape
|
119
|
+
{
|
120
|
+
Plane(){};
|
121
|
+
Plane(Vector3D<float> aN, float aD) : n(aN), d(aD) {};
|
122
|
+
~Plane(){};
|
123
|
+
|
124
|
+
const char* getClassName() const { return "Plane"; }
|
125
|
+
|
126
|
+
void printInfo() const
|
127
|
+
{
|
128
|
+
cout << "** struct: Plane [" << this << "]" << endl;
|
129
|
+
cout << "normal: (" << n.x << ", " << n.y << ", " << n.z <<")" << endl;
|
130
|
+
cout << "d: " << d << endl;
|
131
|
+
}
|
132
|
+
|
133
|
+
Vector3D<float> n; // d = n.dot(x)
|
134
|
+
float d;
|
135
|
+
};
|
136
|
+
|
137
|
+
|
138
|
+
/*
|
139
|
+
*
|
140
|
+
* �ʲ���collision�黻�Ѥˤ����Ȥ��Ƥ��ʤ�
|
141
|
+
*
|
142
|
+
*/
|
143
|
+
|
144
|
+
struct Segment : public Shape
|
145
|
+
{
|
146
|
+
Segment(){};
|
147
|
+
Segment(Vector3D<float> aA, Vector3D<float> aB)
|
148
|
+
{
|
149
|
+
a = aA; b = aB;
|
150
|
+
}
|
151
|
+
~Segment(){};
|
152
|
+
|
153
|
+
const char* getClassName() const { return "Segment"; }
|
154
|
+
|
155
|
+
void printInfo() const
|
156
|
+
{
|
157
|
+
cout << "** struct: Segment [" << this << "]" << endl;
|
158
|
+
cout << "a: (" << a.x << ", " << a.y << ", " << a.z <<")" << endl;
|
159
|
+
cout << "b: (" << b.x << ", " << b.y << ", " << b.z <<")" << endl;
|
160
|
+
}
|
161
|
+
|
162
|
+
Vector3D<float> a;
|
163
|
+
Vector3D<float> b;
|
164
|
+
};
|
165
|
+
|
166
|
+
struct Capsule : public Shape
|
167
|
+
{
|
168
|
+
Capsule(){};
|
169
|
+
~Capsule(){};
|
170
|
+
|
171
|
+
const char* getClassName() const { return "Capsule"; }
|
172
|
+
|
173
|
+
void printInfo() const
|
174
|
+
{
|
175
|
+
cout << "** struct: Capsule [" << this << "]" << endl;
|
176
|
+
cout << "segment: a(" << seg.a.x << ", " << seg.b.y << ", " << seg.b.z <<"), "
|
177
|
+
<< "b(" << seg.b.x << ", " << seg.b.y << ", " << seg.b.z << ")" << endl;
|
178
|
+
cout << "radius: " << r << endl;
|
179
|
+
}
|
180
|
+
|
181
|
+
Segment seg;
|
182
|
+
float r;
|
183
|
+
};
|
184
|
+
|
185
|
+
}
|
186
|
+
#endif
|