Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "OPCODE-1.2/Opcode.h"
- //#include "Opcode.h"
- #include <iostream>
- #include <queue>
- using namespace std;
- using namespace Opcode;
- int main() {
- /////////////////////// Model //////////////////////
- Point vertices[6];
- vertices[0] = Point(1,3,0);
- vertices[1] = Point(1,-1,1);
- vertices[2] = Point(1,-1,-3);
- vertices[3] = Point(0,-1,1);
- vertices[4] = Point(0,-1,-3);
- vertices[5] = Point(-1,-1,1);
- IndexedTriangle triangles[3];
- triangles[0] = IndexedTriangle(0,2,1);
- triangles[1] = IndexedTriangle(0,4,3);
- triangles[2] = IndexedTriangle(1,3,5);
- Opcode::OPCODECREATE creator;
- creator.NbTris = 3;
- //creator.NbTris = aIndices.size()/3;
- creator.NbVerts = 6;
- //creator.Tris = aIndices.getArray();
- creator.Tris = (udword*) triangles;
- creator.Verts = vertices;
- // Tree building settings
- creator.Rules = Opcode::SPLIT_COMPLETE | Opcode::SPLIT_SPLATTERPOINTS | Opcode::SPLIT_GEOMCENTER;
- creator.NoLeaf = false;
- creator.Quantized = false;
- // Debug
- creator.KeepOriginal = true;
- for( int i=0;i<9;++i ) {
- if( i>0 && i%3==0 )
- cout << endl;
- cout << "tri " << i << ": " << creator.Tris[i] << " ";
- }
- cout << endl;
- // 2) Build the model
- Opcode::OPCODE_Model aModel;
- bool Status = aModel.Build(creator);
- if( !Status ) {
- cerr << "building model failed" << endl;
- exit(1);
- } else {
- cout << "created OPCODE model" << endl;// with %i nodes, using %i bytes from %i triangles", aModel.GetNbNodes(), aModel.GetUsedBytes(), aTriangles.size() );
- }
- const AABBTree* tree=aModel.GetSourceTree();
- cout << "tree depth: " << tree->ComputeDepth() << ", is complete " << boolalpha << tree->IsComplete() << ", number of nodes: " << tree->GetNbNodes()
- << ", is leaf: " << boolalpha << tree->IsLeaf() << endl;
- for( int i=0; i<tree->GetNbNodes();++i ) {
- cout << " index: " << tree->GetIndices()[i] << endl;
- }
- queue<const AABBTreeNode*> trees;
- const AABBTreeNode* temp;
- trees.push(aModel.GetSourceTree());
- while(!trees.empty()) {
- cout << "queue size: " << trees.size() << ", node: " << trees.front() << endl;
- cout << " size: " << trees.front()->GetNodeSize() << endl;
- for( int i=0;i<trees.front()->GetNbPrimitives();++i ) {
- int index=trees.front()->GetPrimitives()[i];
- cout << " " << i << ", " << index << ": " << tree->GetIndices()[index] << endl;
- }
- const AABB* aabb = trees.front()->GetAABB();
- Point min,max;
- aabb->GetMin(min);
- aabb->GetMax(max);
- cout << " min: " << min.x << " " << min.y << " " << min.z << ", max: " << max.x << " " << max.y << " " << max.z << endl;
- if( (temp=trees.front()->GetPos()) != 0 ) {
- trees.push(temp);
- }
- if( (temp=trees.front()->GetNeg()) != 0 ) {
- trees.push(temp);
- }
- trees.pop();
- }
- ////////////////////// OBB setup /////////////////////////////////
- Point center(0,0,0);
- Point extents(2,2,2);
- IceMaths::Matrix3x3 transform( 1,0,0, 0,1,0, 0,0,1 );
- OBB obb( center, extents, transform );
- Point corners[8];
- obb.ComputePoints(corners);
- cout << "OBB corners: " << endl;
- for( int i=0; i<8; ++i ) {
- cout << " " << i << ": " << corners[i].x << " " << corners[i].y << " " << corners[i].z << endl;
- }
- for( int i=0;i<(sizeof(vertices)/sizeof(Point));++i) {
- cout << " point " << vertices[i].x << " " << vertices[i].y << " " << vertices[i].z;
- if( obb.ContainsPoint(vertices[i]) ) {
- cout << " contained" << endl;
- } else {
- cout << " not contained" << endl;
- }
- }
- ///////////////////// Collider ///////////////////////////////////
- Opcode::OBBCollider obbCollider;
- obbCollider.SetFirstContact(true);
- obbCollider.SetTemporalCoherence(false);
- obbCollider.SetFullBoxBoxTest(true);
- //3) Setup object callback or pointers:
- obbCollider.SetPointers(triangles, vertices);
- const char* problem = obbCollider.ValidateSettings();
- if( problem==0 ) {
- std::cerr << "settings are fine" << std::endl;
- } else {
- std::cerr << "setting problem: " << problem << std::endl;
- }
- //4) Perform a collision query
- static Opcode::OBBCache cache;
- IceMaths::Matrix4x4 id( 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 );
- bool IsOk = obbCollider.Collide(cache, obb, &aModel);
- if( !IsOk ) {
- std::cerr << "collision detection could not be performed" << std::endl;
- } else {
- cout << "touched primitives: " << obbCollider.GetNbTouchedPrimitives() << ", volume-bv tests: " << obbCollider.GetNbVolumeBVTests() << ", volume-prim tests: " << obbCollider.GetNbVolumePrimTests() << std::endl;
- }
- if( obbCollider.GetContactStatus() ) {
- cout << endl << ":)" << "Collision!" << endl << ":)" << endl;
- } else {
- cout << "No collision!" << endl;
- }
- if( obbCollider.ContactFound() ) {
- cout << "contact found" << endl;
- } else {
- cout << "contact not found" << endl;
- }
- }
- #include "OPCODE-1.2/Opcode.h"
- #include <iostream>
- #include <queue>
- using namespace std;
- using namespace Opcode;
- int main() {
- /////////////////////// Model //////////////////////
- Point vertices[6];
- vertices[0] = Point(1,3,0);
- vertices[1] = Point(1,-1,1);
- vertices[2] = Point(1,-1,-3);
- vertices[3] = Point(0,-1,1);
- vertices[4] = Point(0,-1,-3);
- vertices[5] = Point(-1,-1,1);
- IndexedTriangle triangles[3];
- triangles[0] = IndexedTriangle(0,2,1);
- triangles[1] = IndexedTriangle(0,4,3);
- triangles[2] = IndexedTriangle(1,3,5);
- Opcode::OPCODECREATE creator;
- creator.NbTris = 3;
- //creator.NbTris = aIndices.size()/3;
- creator.NbVerts = 6;
- //creator.Tris = aIndices.getArray();
- creator.Tris = (udword*) triangles;
- creator.Verts = vertices;
- // Tree building settings
- creator.Rules = Opcode::SPLIT_COMPLETE | Opcode::SPLIT_SPLATTERPOINTS | Opcode::SPLIT_GEOMCENTER;
- creator.NoLeaf = false;
- creator.Quantized = false;
- // Debug
- creator.KeepOriginal = true;
- for( int i=0;i<9;++i ) {
- if( i>0 && i%3==0 )
- cout << endl;
- cout << "tri " << i << ": " << creator.Tris[i] << " ";
- }
- cout << endl;
- // 2) Build the model
- Opcode::OPCODE_Model aModel;
- bool Status = aModel.Build(creator);
- if( !Status ) {
- cerr << "building model failed" << endl;
- exit(1);
- } else {
- cout << "created OPCODE model" << endl;// with %i nodes, using %i bytes from %i triangles", aModel.GetNbNodes(), aModel.GetUsedBytes(), aTriangles.size() );
- }
- const AABBTree* tree=aModel.GetSourceTree();
- cout << "tree depth: " << tree->ComputeDepth() << ", is complete " << boolalpha << tree->IsComplete() << ", number of nodes: " << tree->GetNbNodes()
- << ", is leaf: " << boolalpha << tree->IsLeaf() << endl;
- for( int i=0; i<tree->GetNbNodes();++i ) {
- cout << " index: " << tree->GetIndices()[i] << endl;
- }
- queue<const AABBTreeNode*> trees;
- const AABBTreeNode* temp;
- trees.push(aModel.GetSourceTree());
- while(!trees.empty()) {
- cout << "queue size: " << trees.size() << ", node: " << trees.front() << endl;
- cout << " size: " << trees.front()->GetNodeSize() << endl;
- for( int i=0;i<trees.front()->GetNbPrimitives();++i ) {
- int index=trees.front()->GetPrimitives()[i];
- cout << " " << i << ", " << index << ": " << tree->GetIndices()[index] << endl;
- }
- const AABB* aabb = trees.front()->GetAABB();
- Point min,max;
- aabb->GetMin(min);
- aabb->GetMax(max);
- cout << " min: " << min.x << " " << min.y << " " << min.z << ", max: " << max.x << " " << max.y << " " << max.z << endl;
- if( (temp=trees.front()->GetPos()) != 0 ) {
- trees.push(temp);
- }
- if( (temp=trees.front()->GetNeg()) != 0 ) {
- trees.push(temp);
- }
- trees.pop();
- }
- ////////////////////// AABB setup /////////////////////////////////
- Point center(0,0,0);
- Point extents(2,2,2);
- IceMaths::Matrix3x3 transform( 1,0,0, 0,1,0, 0,0,1 );
- AABB aabb;
- aabb.SetCenterExtents(center, extents);
- Point min, max;
- aabb.GetMin(min);
- aabb.GetMax(max);
- cout << "aabb min: " << min.x << " " << min.y << " " << min.z << ", max: " << max.x << " " << max.y << " " << max.z << endl;
- ///////////////////// Collider ///////////////////////////////////
- Opcode::AABBCollider aabbCollider;
- aabbCollider.SetFirstContact(true);
- aabbCollider.SetTemporalCoherence(false);
- //3) Setup object callback or pointers:
- aabbCollider.SetPointers(triangles, vertices);
- const char* problem = aabbCollider.ValidateSettings();
- if( problem==0 ) {
- std::cerr << "settings are fine" << std::endl;
- } else {
- std::cerr << "setting problem: " << problem << std::endl;
- }
- //4) Perform a collision query
- static Opcode::AABBCache cache;
- IceMaths::Matrix4x4 id( 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 );
- bool IsOk = aabbCollider.Collide(cache, aabb, &aModel);
- if( !IsOk ) {
- std::cerr << "collision detection could not be performed" << std::endl;
- } else {
- cout << "touched primitives: " << aabbCollider.GetNbTouchedPrimitives() << ", volume-bv tests: " << aabbCollider.GetNbVolumeBVTests() << ", volume-prim tests: " << aabbCollider.GetNbVolumePrimTests() << std::endl;
- }
- if( aabbCollider.GetContactStatus() ) {
- cout << endl << ":)" << "Collision!" << endl << ":)" << endl;
- } else {
- cout << "No collision!" << endl;
- }
- if( aabbCollider.ContactFound() ) {
- cout << "contact found" << endl;
- } else {
- cout << "contact not found" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement