Chunky by FelipeFS
Chunky by FelipeFS
GPWiki.org
It is currently Sun Sep 21, 2014 8:09 pm

All times are UTC




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: Sun Oct 24, 2004 10:24 pm 
Digerati

Joined: Fri Sep 24, 2004 3:15 am
Posts: 1791
Location: No longer near Boston, MA
... Is driving me nuts :rofl

hooooookay.... I'm using the D3DX.Intersect function, and it just doesn't want to work, the buffer set and get calls I'm using are somehow warpping my mesh, grr........ I'm looking for a way to have "perfect" collision detection with a mesh, w/o the intersect function (or a really in-depth tutorial on the intersect function!) any thoughts, ideas, suggestions, candy? :x

I'm looking for Line-intersecting-plane type stuff, not bounding boxs and spheres, in case that isn't clear --- like being able to make a house/castle mesh and walk around in it :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 24, 2004 10:48 pm 
Technomaniac
User avatar

Joined: Mon Aug 23, 2004 12:24 am
Posts: 3096
Location: Washington , USA
Well, this is actually one of the most complicated things out there! Later in my Physics Series (yes, im still working on it!), I will expand the engine to 3d, and collision detection is by far the hardest thing to do. The math behind rigid body motion is easy, but determining if they hit is harder. You see, the problem is speed. It is possible to have perfect collision detection, but in a game, it would be uber-slow. So we fix it by ditching some accuracy for speed. So the trick is to find that balance between accurate and fast.

That probably didn't help with your research adventure, but at least you get some information. I CAN tell you that, for a castle, BSP would be nice. Or I can link you to this.

The funny thing is that the demo for the tutorial is actually walking around in a castle (go figure)

_________________
GMan
Black Ninja Games
Imagine ASCII art here!


Top
 Profile  
 
PostPosted: Mon Oct 25, 2004 3:24 am 
Ankle Nibbler

Joined: Fri Sep 17, 2004 5:51 pm
Posts: 128
I had problems with that intersect function also. It appears to work, but the calculations seems so different from the 3d mesh world it was in.It drove me bananas! Anyway, I wont have to worry about that for now, concidering I have to start from scratch.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 25, 2004 6:52 am 
Babirusa
User avatar

Joined: Thu Aug 19, 2004 2:55 pm
Posts: 9245
Location: The Netherlands
I got c++ code for you, which works. Simply first create a ray, like you find in the picking example(VB/C++) that comes with the sdk, or from MVPS.org (google: improved ray picking or something)

Code:
   //Check if we hit an object
   //Check if we hit our model:
   DWORD dwNumFaces = g_pGame->objTerrain->objMS3DModel->m_pMS3DFile->GetNumTriangles();
   D3DXVECTOR3 *v0,*v1,*v2;
   D3DXVECTOR3 vv0,vv1,vv2;
   float fBary1, fBary2;
    float fDist;      
   int intersects = 0;


   D3DXVECTOR3 vNear,vDir;
   D3DXMATRIX invMat;
   D3DXMATRIX m_combinedMat;
   //temp: get the transform:
   //g_pGame->mp_d3d_device->GetTransform(D3DTS_WORLD,&m_combinedMat);
    m_combinedMat = g_pGame->objTerrain->matobject;
   D3DXMatrixInverse(&invMat,NULL,&m_combinedMat);
   D3DXVec3TransformCoord(&vNear,&vPickRayOrig,&invMat);
   D3DXVec3TransformNormal(&vDir,&vPickRayDir,&invMat);

   for( DWORD i=0; i<dwNumFaces; i++ )
    {
        g_pGame->objTerrain->objMS3DModel->GetVectorAt((i*3),&v0);
        g_pGame->objTerrain->objMS3DModel->GetVectorAt((i*3)+1,&v1);
        g_pGame->objTerrain->objMS3DModel->GetVectorAt((i*3)+2,&v2);
      vv0 = *v0;
      vv1 = *v1;
      vv2 = *v2;
       // Check if the pick ray passes through this point
        if( IntersectTriangle( vNear, vDir, vv0, vv1, vv2,
                                       &fDist, &fBary1, &fBary2 ) )
      {

         intersects++;
         //Transform vertex back to world space!
         D3DXVECTOR3 vnewpos;
         D3DXVec3TransformCoord(&vnewpos,&vv0,&m_combinedMat);
         g_pGame->m_pCube1->SetPosition(vnewpos.x,vnewpos.y,vnewpos.z);

         break;
      }
   }


IntersectTriangle is simply a functions which checks if a line is going through a triangle, it's probably from gameprogrammer.com or something. (or gametutorials.com).

Now, the most important thing in this code, is that you actually use the MATRIX that was used to render the object on it's place. So, you did your rotation, scaling, translating, etc, and Multiplied it in a new matrix and then did SetTransform.

I simply used a global object for it to test, called matobject. Now, even if I scale my model, ray intersection still works.

btw: first do box intersection, if hit -> proceed triangle intersection :)

hth :)

_________________
Serious game developer

http://www.persistentrealities.com
http://www.persistentrealities.com/vbfibre
http://www.ambiances.nl


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 25, 2004 10:20 am 
Digerati

Joined: Fri Sep 24, 2004 3:15 am
Posts: 1791
Location: No longer near Boston, MA
ok, guys... very nifty! I'll be sure to check it all out :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 25, 2004 2:54 pm 
Carmack Clone
User avatar

Joined: Mon Aug 16, 2004 1:53 am
Posts: 727
http://www.realtimerendering.com/int/

rene


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 25, 2004 3:53 pm 
Digerati

Joined: Fri Sep 24, 2004 3:15 am
Posts: 1791
Location: No longer near Boston, MA
two quick things....
g_pGame->m_pCube1->SetPosition(vnewpos.x,vnewpos.y,vnewpos.z);

err.... what does that do? You don't mention the cube before, though the rest seem to make some sense...

and why do you call break? :x

heh, off to find IntersectTriangle...... :P


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 25, 2004 7:45 pm 
Babirusa
User avatar

Joined: Thu Aug 19, 2004 2:55 pm
Posts: 9245
Location: The Netherlands
Sadistic Penguin wrote:
two quick things....
g_pGame->m_pCube1->SetPosition(vnewpos.x,vnewpos.y,vnewpos.z);

err.... what does that do? You don't mention the cube before, though the rest seem to make some sense...

and why do you call break? :x

heh, off to find IntersectTriangle...... :P


Oh, because I wanted to have a cube to see where I clicked the face. :) It's just an object I use for testing, as you might have noticed on other screenshots.

_________________
Serious game developer

http://www.persistentrealities.com
http://www.persistentrealities.com/vbfibre
http://www.ambiances.nl


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 1:06 am 
Digerati

Joined: Fri Sep 24, 2004 3:15 am
Posts: 1791
Location: No longer near Boston, MA
It seems to be working for my smaller trees, and the problem with the larger ones is just some wacky math I added earlier, so it seems to work like a charm...

Watch me get up close and personal with Jack Hoxley's 3D world Tree :rofl

http://www.geocities.com/sadisticpenguin2000/index.html

Now, on to make a very lame FPS!!! >:D Muahahahahahahhahahahaahahahahaha + 1/2!!!!!!!111!11one

I ended up typing up the code for the intersection from some nifty place, and fooling around with your code, Almar... Turns out there is no GetVectorAt for VB, or you were doing some wacky stuff I couldn't follow :x

I used D3DXMeshVertexBuffer8GetData, but it's kinda slow.... oh well, yet another reason to learn C++! I guess the way to go is split up large meshs, or use some other things to bring down checked triangles...

enough babble... Thanks again!

EDIT: Will D3DXMeshVertexBuffer8GetData get scaling and rotation? (It obviously gets X and Y just dandy....)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 7:29 am 
Babirusa
User avatar

Joined: Thu Aug 19, 2004 2:55 pm
Posts: 9245
Location: The Netherlands
Sadistic Penguin wrote:
It seems to be working for my smaller trees, and the problem with the larger ones is just some wacky math I added earlier, so it seems to work like a charm...

Watch me get up close and personal with Jack Hoxley's 3D world Tree :rofl

http://www.geocities.com/sadisticpenguin2000/index.html

Now, on to make a very lame FPS!!! >:D Muahahahahahahhahahahaahahahahaha + 1/2!!!!!!!111!11one

I ended up typing up the code for the intersection from some nifty place, and fooling around with your code, Almar... Turns out there is no GetVectorAt for VB, or you were doing some wacky stuff I couldn't follow :x

I used D3DXMeshVertexBuffer8GetData, but it's kinda slow.... oh well, yet another reason to learn C++! I guess the way to go is split up large meshs, or use some other things to bring down checked triangles...

enough babble... Thanks again!

EDIT: Will D3DXMeshVertexBuffer8GetData get scaling and rotation? (It obviously gets X and Y just dandy....)


the GetTriangle is just all the triangles of the mesh, looping through all of 'em testing for intersection.

I think transformation is done every frame, in your videocard, and doubt your vertexbuffer will contain the scaled object.. :)

_________________
Serious game developer

http://www.persistentrealities.com
http://www.persistentrealities.com/vbfibre
http://www.ambiances.nl


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 10:24 am 
Digerati

Joined: Fri Sep 24, 2004 3:15 am
Posts: 1791
Location: No longer near Boston, MA
I just used GetNumFaces... the thing I need to replace C++ -> VB is GetVectorAt.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 26, 2004 2:52 pm 
Babirusa
User avatar

Joined: Thu Aug 19, 2004 2:55 pm
Posts: 9245
Location: The Netherlands
Sadistic Penguin wrote:
I just used GetNumFaces... the thing I need to replace C++ -> VB is GetVectorAt.


Get the vertices somehow, maybe ndeed with that vertexbuffer thing, use the world transformation you used to render the object, in the code above, it will effectively transform your RAY to the "world" of the model. When it hits, you transform your ray back to "real" world coordinates.

_________________
Serious game developer

http://www.persistentrealities.com
http://www.persistentrealities.com/vbfibre
http://www.ambiances.nl


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

Powered by phpBB® Forum Software © phpBB Group