Jump to content
  • Advertisement
Sign in to follow this  

problems with picking method

This topic is 4358 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ive implemented the method demonstrated on the toymaker site and am having a problem with the capture area, it seems to respond about halfway up the object and abit further past it, im using the following method http://img518.imageshack.us/img518/4554/00337gc.jpg http://img148.imageshack.us/img148/6505/00349ao.jpg
D3DVIEWPORT9 mainViewport;
m_pd3dDevice->GetViewport( &mainViewport );
m_pd3dDevice->GetTransform(D3DTS_PROJECTION,&matProj);



D3DXVECTOR3 v;
v.x =  ( ( ( 2.0f * mouseX ) / mainViewport.Width ) - 1 ) / matProj._11;
v.y = -( ( ( 2.0f * mouseY ) / mainViewport.Height ) - 1 ) / matProj._22;
v.z =  1.0f;
mousePos = v;

D3DXMATRIX view;
TheCamera->getViewMatrix(&view);
D3DXMatrixInverse( &m, NULL, &view );
// Transform the screen space pick ray into 3D space
rayDir.x = v.x*m._11 + v.y*m._21 + v.z*m._31;
rayDir.y = v.x*m._12 + v.y*m._22 + v.z*m._32;
rayDir.z = v.x*m._13 + v.y*m._23 + v.z*m._33;
rayOrigin.x = m._41;
rayOrigin.y = m._42;
rayOrigin.z = m._43;

// Use inverse of matrix
D3DXMATRIX matInverse;

D3DXMatrixInverse(&matInverse,NULL,&xFiles[0].entityWorld);

// Transform ray origin and direction by inv matrix
D3DXVECTOR3 rayObjOrigin,rayObjDirection;

D3DXVec3TransformCoord(&rayObjOrigin,&rayOrigin,&matInverse);
D3DXVec3TransformNormal(&rayObjDirection,&rayDir,&matInverse);
D3DXVec3Normalize(&rayObjDirection,&rayObjDirection);
float distanceToCollision = 0;

BOOL intersect;
rayIntersect(&xFiles[0],&rayObjOrigin,&rayObjDirection,&distanceToCollision,&intersect);
stringstream ss;
ss << distanceToCollision;
string dist = ss.str();

if (intersect)
{
MessageBox(0,dist.c_str(),"Error",MB_OK);
}
}


void objMan::rayIntersect(CXFileEntity * mesh,D3DXVECTOR3 *rayObjOrigin,D3DXVECTOR3 * rayObjDirection,float *distanceToCollision, BOOL *hit)
{
D3DXIntersect(mesh->xMesh, rayObjOrigin, rayObjDirection,hit, NULL,NULL, NULL, distanceToCollision, NULL, NULL);


}
cheers

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You might want to try: D3DXVec3Unproject

Share this post


Link to post
Share on other sites
You get a point in 3d space with D3DXVec3Unproject.

To get something usable you simply call it two times with different z values. This gets you simply two points in world space. You can use one as the ray origin and use the difference as the ray direction for intersection tests.

Share this post


Link to post
Share on other sites
So as not to duplicate a thread with a similar problem I'll post my problem with picking here. Hope thats the right thing to do.

Anyway I am using Managed DirectX with C++ 2003 .Net 1.1 with the April version of DirectX 9c.

I have a plane drawn 36x36 grids and using examples on various sites on the net I managed to get a picking piece of code up and running but for some reason it is not working. Heres the segments of code involved.


void DXForm::OnMouseDown(Object* sender, MouseEventArgs* pArgs)
{
Viewport vp;
Matrix world;
Matrix view;
Matrix projection;

vp = m_dxbase->Device->Viewport;
world = m_dxbase->Device->Transform->World;
projection = m_dxbase->Device->Transform->Projection;
view = m_dxbase->Device->Transform->View;

Vector3 RayPos;
RayPos = Vector3();
RayPos.X = (float)pArgs->X;
RayPos.Y = (float)pArgs->Y;

Vector3 Near;
Vector3 Far;

Near = Vector3::Unproject(Vector3(RayPos.X,RayPos.Y,0),__box(vp),world,view,projection);
Far = Vector3::Unproject(Vector3(RayPos.X,RayPos.Y,1),__box(vp),world,view,projection);

Vector3 RayDir;
RayDir = Vector3::Subtract(Far,Near);

IntersectInformation* ii = m_plane->PickVertex(RayPos,RayDir);

}






IntersectInformation* DXPlane::PickVertex(Vector3 RayPos,Vector3 RayDir)
{
return m_primitives->PickVertex(RayPos,RayDir);
}






IntersectInformation* DXPrimitive::PickVertex(Vector3 RayPos,Vector3 RayDir)
{
Vector3 tempV3a;
Vector3 tempV3b;
Vector3 tempV3c;
IntersectInformation ii;
FileStream* fs;
StreamWriter* sw;
fs = __gc new FileStream("PickVertex.txt",FileMode::CreateNew);
sw = __gc new StreamWriter(fs);
sw->WriteLine(String::Format("RayPos = {0}, RayDir = {1}",__box(RayPos),__box(RayDir)));

for (int i = 0; i < m_vertexCount-2; i+=3)
{
if (m_cvt == DXBase::CustomVertexType::NormalisedColored)
{
ii = IntersectInformation();
tempV3a = Vector3(m_PNCVerts.X,m_PNCVerts.Y,m_PNCVerts.Z);
tempV3b = Vector3(m_PNCVerts[i+1].X,m_PNCVerts[i+1].Y,m_PNCVerts[i+1].Z);
tempV3c = Vector3(m_PNCVerts[i+2].X,m_PNCVerts[i+2].Y,m_PNCVerts[i+2].Z);
sw->WriteLine(String::Format("i={0}",__box(i)));
sw->WriteLine(String::Format("V3a={0},{1},{2}",__box(tempV3a.X),__box(tempV3a.Y),__box(tempV3a.Z)));
sw->WriteLine(String::Format("V3b={0},{1},{2}",__box(tempV3b.X),__box(tempV3b.Y),__box(tempV3b.Z)));
sw->WriteLine(String::Format("V3c={0},{1},{2}",__box(tempV3c.X),__box(tempV3b.Y),__box(tempV3c.Z)));
bool found = Geometry::IntersectTri(tempV3a,tempV3b,tempV3c,RayPos,RayDir,&ii);
if (found)
{
sw->WriteLine(String::Format("Found : {0}",__box(found)));
i = m_vertexCount;
}
}
}
sw->Close();
return &ii;
}





As you can see I have outputted the values being tested to see why it isn't working. The contents of the file are thus:


RayPos = X: 272,Y: 342,Z: 0
RayDir = X: -0.129,Y: -5.736,Z: 6
i=0
V3a=-70,0,-100
V3b=-65,0,-100
V3c=-60,0,-100
i=3
V3a=-55,0,-100
V3b=-50,0,-100
V3c=-45,0,-100
i=6
V3a=-40,0,-100
V3b=-35,0,-100
V3c=-30,0,-100
i=9
V3a=-25,0,-100
V3b=-20,0,-100
V3c=-15,0,-100
i=12
V3a=-10,0,-100
V3b=-5,0,-100
V3c=0,0,-100
i=15
V3a=5,0,-100
V3b=10,0,-100
V3c=15,0,-100
i=18
V3a=20,0,-100
V3b=25,0,-100
V3c=30,0,-100
i=21
V3a=35,0,-100
V3b=40,0,-100
V3c=45,0,-100
i=24
V3a=50,0,-100
V3b=55,0,-100
V3c=60,0,-100
i=27
V3a=65,0,-100
V3b=70,0,-100
V3c=75,0,-100
i=30
V3a=80,0,-100
V3b=85,0,-100
V3c=90,0,-100
i=33
V3a=95,0,-100
V3b=100,0,-100
V3c=105,0,-100
i=36
V3a=110,0,-100
V3b=-70,0,-95
V3c=-65,0,-95
i=39
V3a=-60,0,-95
V3b=-55,0,-95
V3c=-50,0,-95
i=42
V3a=-45,0,-95
V3b=-40,0,-95
V3c=-35,0,-95
i=45
V3a=-30,0,-95
V3b=-25,0,-95
V3c=-20,0,-95
i=48
V3a=-15,0,-95
V3b=-10,0,-95
V3c=-5,0,-95
i=51
V3a=0,0,-95
V3b=5,0,-95
V3c=10,0,-95
i=54
V3a=15,0,-95
V3b=20,0,-95
V3c=25,0,-95
i=57
V3a=30,0,-95
V3b=35,0,-95
V3c=40,0,-95
i=60
V3a=45,0,-95
V3b=50,0,-95
V3c=55,0,-95
i=63
V3a=60,0,-95
V3b=65,0,-95
V3c=70,0,-95
i=66
V3a=75,0,-95
V3b=80,0,-95
V3c=85,0,-95
i=69
V3a=90,0,-95
V3b=95,0,-95
V3c=100,0,-95
i=72
V3a=105,0,-95
V3b=110,0,-95
V3c=-70,0,-90
i=75
V3a=-65,0,-90
V3b=-60,0,-90
V3c=-55,0,-90
i=78
V3a=-50,0,-90
V3b=-45,0,-90
V3c=-40,0,-90
i=81
V3a=-35,0,-90
V3b=-30,0,-90
V3c=-25,0,-90
i=84
V3a=-20,0,-90
V3b=-15,0,-90
V3c=-10,0,-90
i=87
V3a=-5,0,-90
V3b=0,0,-90
V3c=5,0,-90
i=90
V3a=10,0,-90
V3b=15,0,-90
V3c=20,0,-90
i=93
V3a=25,0,-90
V3b=30,0,-90
V3c=35,0,-90
i=96
V3a=40,0,-90
V3b=45,0,-90
V3c=50,0,-90
i=99
V3a=55,0,-90
V3b=60,0,-90
V3c=65,0,-90
i=102
V3a=70,0,-90
V3b=75,0,-90
V3c=80,0,-90
i=105
V3a=85,0,-90
V3b=90,0,-90
V3c=95,0,-90
i=108
V3a=100,0,-90
V3b=105,0,-90
V3c=110,0,-90
i=111
V3a=-70,0,-85
V3b=-65,0,-85
V3c=-60,0,-85
i=114
V3a=-55,0,-85
V3b=-50,0,-85
V3c=-45,0,-85
i=117
V3a=-40,0,-85
V3b=-35,0,-85
V3c=-30,0,-85
i=120
V3a=-25,0,-85
V3b=-20,0,-85
V3c=-15,0,-85
i=123
V3a=-10,0,-85
V3b=-5,0,-85
V3c=0,0,-85
i=126
V3a=5,0,-85
V3b=10,0,-85
V3c=15,0,-85
i=129
V3a=20,0,-85
V3b=25,0,-85
V3c=30,0,-85
i=132
V3a=35,0,-85
V3b=40,0,-85
V3c=45,0,-85
i=135
V3a=50,0,-85
V3b=55,0,-85
V3c=60,0,-85
i=138
V3a=65,0,-85
V3b=70,0,-85
V3c=75,0,-85
i=141
V3a=80,0,-85
V3b=85,0,-85
V3c=90,0,-85
i=144
V3a=95,0,-85
V3b=100,0,-85
V3c=105,0,-85
i=147
V3a=110,0,-85
V3b=-70,0,-80
V3c=-65,0,-80
i=150
V3a=-60,0,-80
V3b=-55,0,-80
V3c=-50,0,-80
i=153
V3a=-45,0,-80
V3b=-40,0,-80
V3c=-35,0,-80
i=156
V3a=-30,0,-80
V3b=-25,0,-80
V3c=-20,0,-80
i=159
V3a=-15,0,-80
V3b=-10,0,-80
V3c=-5,0,-80
i=162
V3a=0,0,-80
V3b=5,0,-80
V3c=10,0,-80
i=165
V3a=15,0,-80
V3b=20,0,-80
V3c=25,0,-80
i=168
V3a=30,0,-80
V3b=35,0,-80
V3c=40,0,-80
i=171
V3a=45,0,-80
V3b=50,0,-80
V3c=55,0,-80
i=174
V3a=60,0,-80
V3b=65,0,-80
V3c=70,0,-80
i=177
V3a=75,0,-80
V3b=80,0,-80
V3c=85,0,-80
i=180
V3a=90,0,-80
V3b=95,0,-80
V3c=100,0,-80
i=183
V3a=105,0,-80
V3b=110,0,-80
V3c=-70,0,-75
i=186
V3a=-65,0,-75
V3b=-60,0,-75
V3c=-55,0,-75
i=189
V3a=-50,0,-75
V3b=-45,0,-75
V3c=-40,0,-75
i=192
V3a=-35,0,-75
V3b=-30,0,-75
V3c=-25,0,-75
i=195
V3a=-20,0,-75
V3b=-15,0,-75
V3c=-10,0,-75
i=198
V3a=-5,0,-75
V3b=0,0,-75
V3c=5,0,-75
i=201
V3a=10,0,-75
V3b=15,0,-75
V3c=20,0,-75
i=204
V3a=25,0,-75
V3b=30,0,-75
V3c=35,0,-75
i=207
V3a=40,0,-75
V3b=45,0,-75
V3c=50,0,-75
i=210
V3a=55,0,-75
V3b=60,0,-75
V3c=65,0,-75
i=213
V3a=70,0,-75
V3b=75,0,-75
V3c=80,0,-75
i=216
V3a=85,0,-75
V3b=90,0,-75
V3c=95,0,-75
i=219
V3a=100,0,-75
V3b=105,0,-75
V3c=110,0,-75
i=222
V3a=-70,0,-70
V3b=-65,0,-70
V3c=-60,0,-70
i=225
V3a=-55,0,-70
V3b=-50,0,-70
V3c=-45,0,-70
i=228
V3a=-40,0,-70
V3b=-35,0,-70
V3c=-30,0,-70
i=231
V3a=-25,0,-70
V3b=-20,0,-70
V3c=-15,0,-70
i=234
V3a=-10,0,-70
V3b=-5,0,-70
V3c=0,0,-70
i=237
V3a=5,0,-70
V3b=10,0,-70
V3c=15,0,-70
i=240
V3a=20,0,-70
V3b=25,0,-70
V3c=30,0,-70
i=243
V3a=35,0,-70
V3b=40,0,-70
V3c=45,0,-70
i=246
V3a=50,0,-70
V3b=55,0,-70
V3c=60,0,-70
i=249
V3a=65,0,-70
V3b=70,0,-70
V3c=75,0,-70
i=252
V3a=80,0,-70
V3b=85,0,-70
V3c=90,0,-70
i=255
V3a=95,0,-70
V3b=100,0,-70
V3c=105,0,-70
i=258
V3a=110,0,-70
V3b=-70,0,-65
V3c=-65,0,-65
i=261
V3a=-60,0,-65
V3b=-55,0,-65
V3c=-50,0,-65
i=264
V3a=-45,0,-65
V3b=-40,0,-65
V3c=-35,0,-65
i=267
V3a=-30,0,-65
V3b=-25,0,-65
V3c=-20,0,-65
i=270
V3a=-15,0,-65
V3b=-10,0,-65
V3c=-5,0,-65
i=273
V3a=0,0,-65
V3b=5,0,-65
V3c=10,0,-65
i=276
V3a=15,0,-65
V3b=20,0,-65
V3c=25,0,-65
i=279
V3a=30,0,-65
V3b=35,0,-65
V3c=40,0,-65
i=282
V3a=45,0,-65
V3b=50,0,-65
V3c=55,0,-65
i=285
V3a=60,0,-65
V3b=65,0,-65
V3c=70,0,-65
i=288
V3a=75,0,-65
V3b=80,0,-65
V3c=85,0,-65
i=291
V3a=90,0,-65
V3b=95,0,-65
V3c=100,0,-65
i=294
V3a=105,0,-65
V3b=110,0,-65
V3c=-70,0,-60
i=297
V3a=-65,0,-60
V3b=-60,0,-60
V3c=-55,0,-60
i=300
V3a=-50,0,-60
V3b=-45,0,-60
V3c=-40,0,-60
i=303
V3a=-35,0,-60
V3b=-30,0,-60
V3c=-25,0,-60
i=306
V3a=-20,0,-60
V3b=-15,0,-60
V3c=-10,0,-60
i=309
V3a=-5,0,-60
V3b=0,0,-60
V3c=5,0,-60
i=312
V3a=10,0,-60
V3b=15,0,-60
V3c=20,0,-60
i=315
V3a=25,0,-60
V3b=30,0,-60
V3c=35,0,-60
i=318
V3a=40,0,-60
V3b=45,0,-60
V3c=50,0,-60
i=321
V3a=55,0,-60
V3b=60,0,-60
V3c=65,0,-60
i=324
V3a=70,0,-60
V3b=75,0,-60
V3c=80,0,-60
i=327
V3a=85,0,-60
V3b=90,0,-60
V3c=95,0,-60
i=330
V3a=100,0,-60
V3b=105,0,-60
V3c=110,0,-60
i=333
V3a=-70,0,-55
V3b=-65,0,-55
V3c=-60,0,-55
i=336
V3a=-55,0,-55
V3b=-50,0,-55
V3c=-45,0,-55
i=339
V3a=-40,0,-55
V3b=-35,0,-55
V3c=-30,0,-55
i=342
V3a=-25,0,-55
V3b=-20,0,-55
V3c=-15,0,-55
i=345
V3a=-10,0,-55
V3b=-5,0,-55
V3c=0,0,-55
i=348
V3a=5,0,-55
V3b=10,0,-55
V3c=15,0,-55
i=351
V3a=20,0,-55
V3b=25,0,-55
V3c=30,0,-55
i=354
V3a=35,0,-55
V3b=40,0,-55
V3c=45,0,-55
i=357
V3a=50,0,-55
V3b=55,0,-55
V3c=60,0,-55
i=360
V3a=65,0,-55
V3b=70,0,-55
V3c=75,0,-55
i=363
V3a=80,0,-55
V3b=85,0,-55
V3c=90,0,-55
i=366
V3a=95,0,-55
V3b=100,0,-55
V3c=105,0,-55
i=369
V3a=110,0,-55
V3b=-70,0,-50
V3c=-65,0,-50
i=372
V3a=-60,0,-50
V3b=-55,0,-50
V3c=-50,0,-50
i=375
V3a=-45,0,-50
V3b=-40,0,-50
V3c=-35,0,-50
i=378
V3a=-30,0,-50
V3b=-25,0,-50
V3c=-20,0,-50
i=381
V3a=-15,0,-50
V3b=-10,0,-50
V3c=-5,0,-50
i=384
V3a=0,0,-50
V3b=5,0,-50
V3c=10,0,-50
i=387
V3a=15,0,-50
V3b=20,0,-50
V3c=25,0,-50
i=390
V3a=30,0,-50
V3b=35,0,-50
V3c=40,0,-50
i=393
V3a=45,0,-50
V3b=50,0,-50
V3c=55,0,-50
i=396
V3a=60,0,-50
V3b=65,0,-50
V3c=70,0,-50
i=399
V3a=75,0,-50
V3b=80,0,-50
V3c=85,0,-50
i=402
V3a=90,0,-50
V3b=95,0,-50
V3c=100,0,-50
i=405
V3a=105,0,-50
V3b=110,0,-50
V3c=-70,0,-45
i=408
V3a=-65,0,-45
V3b=-60,0,-45
V3c=-55,0,-45
i=411
V3a=-50,0,-45
V3b=-45,0,-45
V3c=-40,0,-45
i=414
V3a=-35,0,-45
V3b=-30,0,-45
V3c=-25,0,-45
i=417
V3a=-20,0,-45
V3b=-15,0,-45
V3c=-10,0,-45
i=420
V3a=-5,0,-45
V3b=0,0,-45
V3c=5,0,-45
i=423
V3a=10,0,-45
V3b=15,0,-45
V3c=20,0,-45
i=426
V3a=25,0,-45
V3b=30,0,-45
V3c=35,0,-45
i=429
V3a=40,0,-45
V3b=45,0,-45
V3c=50,0,-45
i=432
V3a=55,0,-45
V3b=60,0,-45
V3c=65,0,-45
i=435
V3a=70,0,-45
V3b=75,0,-45
V3c=80,0,-45
i=438
V3a=85,0,-45
V3b=90,0,-45
V3c=95,0,-45
i=441
V3a=100,0,-45
V3b=105,0,-45
V3c=110,0,-45
i=444
V3a=-70,0,-40
V3b=-65,0,-40
V3c=-60,0,-40
i=447
V3a=-55,0,-40
V3b=-50,0,-40
V3c=-45,0,-40
i=450
V3a=-40,0,-40
V3b=-35,0,-40
V3c=-30,0,-40
i=453
V3a=-25,0,-40
V3b=-20,0,-40
V3c=-15,0,-40
i=456
V3a=-10,0,-40
V3b=-5,0,-40
V3c=0,0,-40
i=459
V3a=5,0,-40
V3b=10,0,-40
V3c=15,0,-40
i=462
V3a=20,0,-40
V3b=25,0,-40
V3c=30,0,-40
i=465
V3a=35,0,-40
V3b=40,0,-40
V3c=45,0,-40
i=468
V3a=50,0,-40
V3b=55,0,-40
V3c=60,0,-40
i=471
V3a=65,0,-40
V3b=70,0,-40
V3c=75,0,-40
i=474
V3a=80,0,-40
V3b=85,0,-40
V3c=90,0,-40
i=477
V3a=95,0,-40
V3b=100,0,-40
V3c=105,0,-40
i=480
V3a=110,0,-40
V3b=-70,0,-35
V3c=-65,0,-35
i=483
V3a=-60,0,-35
V3b=-55,0,-35
V3c=-50,0,-35
i=486
V3a=-45,0,-35
V3b=-40,0,-35
V3c=-35,0,-35
i=489
V3a=-30,0,-35
V3b=-25,0,-35
V3c=-20,0,-35
i=492
V3a=-15,0,-35
V3b=-10,0,-35
V3c=-5,0,-35
i=495
V3a=0,0,-35
V3b=5,0,-35
V3c=10,0,-35
i=498
V3a=15,0,-35
V3b=20,0,-35
V3c=25,0,-35
i=501
V3a=30,0,-35
V3b=35,0,-35
V3c=40,0,-35
i=504
V3a=45,0,-35
V3b=50,0,-35
V3c=55,0,-35
i=507
V3a=60,0,-35
V3b=65,0,-35
V3c=70,0,-35
i=510
V3a=75,0,-35
V3b=80,0,-35
V3c=85,0,-35
i=513
V3a=90,0,-35
V3b=95,0,-35
V3c=100,0,-35
i=516
V3a=105,0,-35
V3b=110,0,-35
V3c=-70,0,-30
i=519
V3a=-65,0,-30
V3b=-60,0,-30
V3c=-55,0,-30
i=522
V3a=-50,0,-30
V3b=-45,0,-30
V3c=-40,0,-30
i=525
V3a=-35,0,-30
V3b=-30,0,-30
V3c=-25,0,-30
i=528
V3a=-20,0,-30
V3b=-15,0,-30
V3c=-10,0,-30
i=531
V3a=-5,0,-30
V3b=0,0,-30
V3c=5,0,-30
i=534
V3a=10,0,-30
V3b=15,0,-30
V3c=20,0,-30
i=537
V3a=25,0,-30
V3b=30,0,-30
V3c=35,0,-30
i=540
V3a=40,0,-30
V3b=45,0,-30
V3c=50,0,-30
i=543
V3a=55,0,-30
V3b=60,0,-30
V3c=65,0,-30
i=546
V3a=70,0,-30
V3b=75,0,-30
V3c=80,0,-30
i=549
V3a=85,0,-30
V3b=90,0,-30
V3c=95,0,-30
i=552
V3a=100,0,-30
V3b=105,0,-30
V3c=110,0,-30
i=555
V3a=-70,0,-25
V3b=-65,0,-25
V3c=-60,0,-25
i=558
V3a=-55,0,-25
V3b=-50,0,-25
V3c=-45,0,-25
i=561
V3a=-40,0,-25
V3b=-35,0,-25
V3c=-30,0,-25
i=564
V3a=-25,0,-25
V3b=-20,0,-25
V3c=-15,0,-25
i=567
V3a=-10,0,-25
V3b=-5,0,-25
V3c=0,0,-25
i=570
V3a=5,0,-25
V3b=10,0,-25
V3c=15,0,-25
i=573
V3a=20,0,-25
V3b=25,0,-25
V3c=30,0,-25
i=576
V3a=35,0,-25
V3b=40,0,-25
V3c=45,0,-25
i=579
V3a=50,0,-25
V3b=55,0,-25
V3c=60,0,-25
i=582
V3a=65,0,-25
V3b=70,0,-25
V3c=75,0,-25
i=585
V3a=80,0,-25
V3b=85,0,-25
V3c=90,0,-25
i=588
V3a=95,0,-25
V3b=100,0,-25
V3c=105,0,-25
i=591
V3a=110,0,-25
V3b=-70,0,-20
V3c=-65,0,-20
i=594
V3a=-60,0,-20
V3b=-55,0,-20
V3c=-50,0,-20
i=597
V3a=-45,0,-20
V3b=-40,0,-20
V3c=-35,0,-20
i=600
V3a=-30,0,-20
V3b=-25,0,-20
V3c=-20,0,-20
i=603
V3a=-15,0,-20
V3b=-10,0,-20
V3c=-5,0,-20
i=606
V3a=0,0,-20
V3b=5,0,-20
V3c=10,0,-20
i=609
V3a=15,0,-20
V3b=20,0,-20
V3c=25,0,-20
i=612
V3a=30,0,-20
V3b=35,0,-20
V3c=40,0,-20
i=615
V3a=45,0,-20
V3b=50,0,-20
V3c=55,0,-20
i=618
V3a=60,0,-20
V3b=65,0,-20
V3c=70,0,-20
i=621
V3a=75,0,-20
V3b=80,0,-20
V3c=85,0,-20
i=624
V3a=90,0,-20
V3b=95,0,-20
V3c=100,0,-20
i=627
V3a=105,0,-20
V3b=110,0,-20
V3c=-70,0,-15
i=630
V3a=-65,0,-15
V3b=-60,0,-15
V3c=-55,0,-15
i=633
V3a=-50,0,-15
V3b=-45,0,-15
V3c=-40,0,-15
i=636
V3a=-35,0,-15
V3b=-30,0,-15
V3c=-25,0,-15
i=639
V3a=-20,0,-15
V3b=-15,0,-15
V3c=-10,0,-15
i=642
V3a=-5,0,-15
V3b=0,0,-15
V3c=5,0,-15
i=645
V3a=10,0,-15
V3b=15,0,-15
V3c=20,0,-15
i=648
V3a=25,0,-15
V3b=30,0,-15
V3c=35,0,-15
i=651
V3a=40,0,-15
V3b=45,0,-15
V3c=50,0,-15
i=654
V3a=55,0,-15
V3b=60,0,-15
V3c=65,0,-15
i=657
V3a=70,0,-15
V3b=75,0,-15
V3c=80,0,-15
i=660
V3a=85,0,-15
V3b=90,0,-15
V3c=95,0,-15
i=663
V3a=100,0,-15
V3b=105,0,-15
V3c=110,0,-15
i=666
V3a=-70,0,-10
V3b=-65,0,-10
V3c=-60,0,-10
i=669
V3a=-55,0,-10
V3b=-50,0,-10
V3c=-45,0,-10
i=672
V3a=-40,0,-10
V3b=-35,0,-10
V3c=-30,0,-10
i=675
V3a=-25,0,-10
V3b=-20,0,-10
V3c=-15,0,-10
i=678
V3a=-10,0,-10
V3b=-5,0,-10
V3c=0,0,-10
i=681
V3a=5,0,-10
V3b=10,0,-10
V3c=15,0,-10
i=684
V3a=20,0,-10
V3b=25,0,-10
V3c=30,0,-10
i=687
V3a=35,0,-10
V3b=40,0,-10
V3c=45,0,-10
i=690
V3a=50,0,-10
V3b=55,0,-10
V3c=60,0,-10
i=693
V3a=65,0,-10
V3b=70,0,-10
V3c=75,0,-10
i=696
V3a=80,0,-10
V3b=85,0,-10
V3c=90,0,-10
i=699
V3a=95,0,-10
V3b=100,0,-10
V3c=105,0,-10
i=702
V3a=110,0,-10
V3b=-70,0,-5
V3c=-65,0,-5
i=705
V3a=-60,0,-5
V3b=-55,0,-5
V3c=-50,0,-5
i=708
V3a=-45,0,-5
V3b=-40,0,-5
V3c=-35,0,-5
i=711
V3a=-30,0,-5
V3b=-25,0,-5
V3c=-20,0,-5
i=714
V3a=-15,0,-5
V3b=-10,0,-5
V3c=-5,0,-5
i=717
V3a=0,0,-5
V3b=5,0,-5
V3c=10,0,-5
i=720
V3a=15,0,-5
V3b=20,0,-5
V3c=25,0,-5
i=723
V3a=30,0,-5
V3b=35,0,-5
V3c=40,0,-5
i=726
V3a=45,0,-5
V3b=50,0,-5
V3c=55,0,-5
i=729
V3a=60,0,-5
V3b=65,0,-5
V3c=70,0,-5
i=732
V3a=75,0,-5
V3b=80,0,-5
V3c=85,0,-5
i=735
V3a=90,0,-5
V3b=95,0,-5
V3c=100,0,-5
i=738
V3a=105,0,-5
V3b=110,0,-5
V3c=-70,0,0
i=741
V3a=-65,0,0
V3b=-60,0,0
V3c=-55,0,0
i=744
V3a=-50,0,0
V3b=-45,0,0
V3c=-40,0,0
i=747
V3a=-35,0,0
V3b=-30,0,0
V3c=-25,0,0
i=750
V3a=-20,0,0
V3b=-15,0,0
V3c=-10,0,0
i=753
V3a=-5,0,0
V3b=0,0,0
V3c=5,0,0
i=756
V3a=10,0,0
V3b=15,0,0
V3c=20,0,0
i=759
V3a=25,0,0
V3b=30,0,0
V3c=35,0,0
i=762
V3a=40,0,0
V3b=45,0,0
V3c=50,0,0
i=765
V3a=55,0,0
V3b=60,0,0
V3c=65,0,0
i=768
V3a=70,0,0
V3b=75,0,0
V3c=80,0,0
i=771
V3a=85,0,0
V3b=90,0,0
V3c=95,0,0
i=774
V3a=100,0,0
V3b=105,0,0
V3c=110,0,0
i=777
V3a=-70,0,5
V3b=-65,0,5
V3c=-60,0,5
i=780
V3a=-55,0,5
V3b=-50,0,5
V3c=-45,0,5
i=783
V3a=-40,0,5
V3b=-35,0,5
V3c=-30,0,5
i=786
V3a=-25,0,5
V3b=-20,0,5
V3c=-15,0,5
i=789
V3a=-10,0,5
V3b=-5,0,5
V3c=0,0,5
i=792
V3a=5,0,5
V3b=10,0,5
V3c=15,0,5
i=795
V3a=20,0,5
V3b=25,0,5
V3c=30,0,5
i=798
V3a=35,0,5
V3b=40,0,5
V3c=45,0,5
i=801
V3a=50,0,5
V3b=55,0,5
V3c=60,0,5
i=804
V3a=65,0,5
V3b=70,0,5
V3c=75,0,5
i=807
V3a=80,0,5
V3b=85,0,5
V3c=90,0,5
i=810
V3a=95,0,5
V3b=100,0,5
V3c=105,0,5
i=813
V3a=110,0,5
V3b=-70,0,10
V3c=-65,0,10
i=816
V3a=-60,0,10
V3b=-55,0,10
V3c=-50,0,10
i=819
V3a=-45,0,10
V3b=-40,0,10
V3c=-35,0,10
i=822
V3a=-30,0,10
V3b=-25,0,10
V3c=-20,0,10
i=825
V3a=-15,0,10
V3b=-10,0,10
V3c=-5,0,10
i=828
V3a=0,0,10
V3b=5,0,10
V3c=10,0,10
i=831
V3a=15,0,10
V3b=20,0,10
V3c=25,0,10
i=834
V3a=30,0,10
V3b=35,0,10
V3c=40,0,10
i=837
V3a=45,0,10
V3b=50,0,10
V3c=55,0,10
i=840
V3a=60,0,10
V3b=65,0,10
V3c=70,0,10
i=843
V3a=75,0,10
V3b=80,0,10
V3c=85,0,10
i=846
V3a=90,0,10
V3b=95,0,10
V3c=100,0,10
i=849
V3a=105,0,10
V3b=110,0,10
V3c=-70,0,15
i=852
V3a=-65,0,15
V3b=-60,0,15
V3c=-55,0,15
i=855
V3a=-50,0,15
V3b=-45,0,15
V3c=-40,0,15
i=858
V3a=-35,0,15
V3b=-30,0,15
V3c=-25,0,15
i=861
V3a=-20,0,15
V3b=-15,0,15
V3c=-10,0,15
i=864
V3a=-5,0,15
V3b=0,0,15
V3c=5,0,15
i=867
V3a=10,0,15
V3b=15,0,15
V3c=20,0,15
i=870
V3a=25,0,15
V3b=30,0,15
V3c=35,0,15
i=873
V3a=40,0,15
V3b=45,0,15
V3c=50,0,15
i=876
V3a=55,0,15
V3b=60,0,15
V3c=65,0,15
i=879
V3a=70,0,15
V3b=75,0,15
V3c=80,0,15
i=882
V3a=85,0,15
V3b=90,0,15
V3c=95,0,15
i=885
V3a=100,0,15
V3b=105,0,15
V3c=110,0,15
i=888
V3a=-70,0,20
V3b=-65,0,20
V3c=-60,0,20
i=891
V3a=-55,0,20
V3b=-50,0,20
V3c=-45,0,20
i=894
V3a=-40,0,20
V3b=-35,0,20
V3c=-30,0,20
i=897
V3a=-25,0,20
V3b=-20,0,20
V3c=-15,0,20
i=900
V3a=-10,0,20
V3b=-5,0,20
V3c=0,0,20
i=903
V3a=5,0,20
V3b=10,0,20
V3c=15,0,20
i=906
V3a=20,0,20
V3b=25,0,20
V3c=30,0,20
i=909
V3a=35,0,20
V3b=40,0,20
V3c=45,0,20
i=912
V3a=50,0,20
V3b=55,0,20
V3c=60,0,20
i=915
V3a=65,0,20
V3b=70,0,20
V3c=75,0,20
i=918
V3a=80,0,20
V3b=85,0,20
V3c=90,0,20
i=921
V3a=95,0,20
V3b=100,0,20
V3c=105,0,20
i=924
V3a=110,0,20
V3b=-70,0,25
V3c=-65,0,25
i=927
V3a=-60,0,25
V3b=-55,0,25
V3c=-50,0,25
i=930
V3a=-45,0,25
V3b=-40,0,25
V3c=-35,0,25
i=933
V3a=-30,0,25
V3b=-25,0,25
V3c=-20,0,25
i=936
V3a=-15,0,25
V3b=-10,0,25
V3c=-5,0,25
i=939
V3a=0,0,25
V3b=5,0,25
V3c=10,0,25
i=942
V3a=15,0,25
V3b=20,0,25
V3c=25,0,25
i=945
V3a=30,0,25
V3b=35,0,25
V3c=40,0,25
i=948
V3a=45,0,25
V3b=50,0,25
V3c=55,0,25
i=951
V3a=60,0,25
V3b=65,0,25
V3c=70,0,25
i=954
V3a=75,0,25
V3b=80,0,25
V3c=85,0,25
i=957
V3a=90,0,25
V3b=95,0,25
V3c=100,0,25
i=960
V3a=105,0,25
V3b=110,0,25
V3c=-70,0,30
i=963
V3a=-65,0,30
V3b=-60,0,30
V3c=-55,0,30
i=966
V3a=-50,0,30
V3b=-45,0,30
V3c=-40,0,30
i=969
V3a=-35,0,30
V3b=-30,0,30
V3c=-25,0,30
i=972
V3a=-20,0,30
V3b=-15,0,30
V3c=-10,0,30
i=975
V3a=-5,0,30
V3b=0,0,30
V3c=5,0,30
i=978
V3a=10,0,30
V3b=15,0,30
V3c=20,0,30
i=981
V3a=25,0,30
V3b=30,0,30
V3c=35,0,30
i=984
V3a=40,0,30
V3b=45,0,30
V3c=50,0,30
i=987
V3a=55,0,30
V3b=60,0,30
V3c=65,0,30
i=990
V3a=70,0,30
V3b=75,0,30
V3c=80,0,30
i=993
V3a=85,0,30
V3b=90,0,30
V3c=95,0,30
i=996
V3a=100,0,30
V3b=105,0,30
V3c=110,0,30
i=999
V3a=-70,0,35
V3b=-65,0,35
V3c=-60,0,35
i=1002
V3a=-55,0,35
V3b=-50,0,35
V3c=-45,0,35
i=1005
V3a=-40,0,35
V3b=-35,0,35
V3c=-30,0,35
i=1008
V3a=-25,0,35
V3b=-20,0,35
V3c=-15,0,35
i=1011
V3a=-10,0,35
V3b=-5,0,35
V3c=0,0,35
i=1014
V3a=5,0,35
V3b=10,0,35
V3c=15,0,35
i=1017
V3a=20,0,35
V3b=25,0,35
V3c=30,0,35
i=1020
V3a=35,0,35
V3b=40,0,35
V3c=45,0,35
i=1023
V3a=50,0,35
V3b=55,0,35
V3c=60,0,35
i=1026
V3a=65,0,35
V3b=70,0,35
V3c=75,0,35
i=1029
V3a=80,0,35
V3b=85,0,35
V3c=90,0,35
i=1032
V3a=95,0,35
V3b=100,0,35
V3c=105,0,35
i=1035
V3a=110,0,35
V3b=-70,0,40
V3c=-65,0,40
i=1038
V3a=-60,0,40
V3b=-55,0,40
V3c=-50,0,40
i=1041
V3a=-45,0,40
V3b=-40,0,40
V3c=-35,0,40
i=1044
V3a=-30,0,40
V3b=-25,0,40
V3c=-20,0,40
i=1047
V3a=-15,0,40
V3b=-10,0,40
V3c=-5,0,40
i=1050
V3a=0,0,40
V3b=5,0,40
V3c=10,0,40
i=1053
V3a=15,0,40
V3b=20,0,40
V3c=25,0,40
i=1056
V3a=30,0,40
V3b=35,0,40
V3c=40,0,40
i=1059
V3a=45,0,40
V3b=50,0,40
V3c=55,0,40
i=1062
V3a=60,0,40
V3b=65,0,40
V3c=70,0,40
i=1065
V3a=75,0,40
V3b=80,0,40
V3c=85,0,40
i=1068
V3a=90,0,40
V3b=95,0,40
V3c=100,0,40
i=1071
V3a=105,0,40
V3b=110,0,40
V3c=-70,0,45
i=1074
V3a=-65,0,45
V3b=-60,0,45
V3c=-55,0,45
i=1077
V3a=-50,0,45
V3b=-45,0,45
V3c=-40,0,45
i=1080
V3a=-35,0,45
V3b=-30,0,45
V3c=-25,0,45
i=1083
V3a=-20,0,45
V3b=-15,0,45
V3c=-10,0,45
i=1086
V3a=-5,0,45
V3b=0,0,45
V3c=5,0,45
i=1089
V3a=10,0,45
V3b=15,0,45
V3c=20,0,45
i=1092
V3a=25,0,45
V3b=30,0,45
V3c=35,0,45
i=1095
V3a=40,0,45
V3b=45,0,45
V3c=50,0,45
i=1098
V3a=55,0,45
V3b=60,0,45
V3c=65,0,45
i=1101
V3a=70,0,45
V3b=75,0,45
V3c=80,0,45
i=1104
V3a=85,0,45
V3b=90,0,45
V3c=95,0,45
i=1107
V3a=100,0,45
V3b=105,0,45
V3c=110,0,45
i=1110
V3a=-70,0,50
V3b=-65,0,50
V3c=-60,0,50
i=1113
V3a=-55,0,50
V3b=-50,0,50
V3c=-45,0,50
i=1116
V3a=-40,0,50
V3b=-35,0,50
V3c=-30,0,50
i=1119
V3a=-25,0,50
V3b=-20,0,50
V3c=-15,0,50
i=1122
V3a=-10,0,50
V3b=-5,0,50
V3c=0,0,50
i=1125
V3a=5,0,50
V3b=10,0,50
V3c=15,0,50
i=1128
V3a=20,0,50
V3b=25,0,50
V3c=30,0,50
i=1131
V3a=35,0,50
V3b=40,0,50
V3c=45,0,50
i=1134
V3a=50,0,50
V3b=55,0,50
V3c=60,0,50
i=1137
V3a=65,0,50
V3b=70,0,50
V3c=75,0,50
i=1140
V3a=80,0,50
V3b=85,0,50
V3c=90,0,50
i=1143
V3a=95,0,50
V3b=100,0,50
V3c=105,0,50
i=1146
V3a=110,0,50
V3b=-70,0,55
V3c=-65,0,55
i=1149
V3a=-60,0,55
V3b=-55,0,55
V3c=-50,0,55
i=1152
V3a=-45,0,55
V3b=-40,0,55
V3c=-35,0,55
i=1155
V3a=-30,0,55
V3b=-25,0,55
V3c=-20,0,55
i=1158
V3a=-15,0,55
V3b=-10,0,55
V3c=-5,0,55
i=1161
V3a=0,0,55
V3b=5,0,55
V3c=10,0,55
i=1164
V3a=15,0,55
V3b=20,0,55
V3c=25,0,55
i=1167
V3a=30,0,55
V3b=35,0,55
V3c=40,0,55
i=1170
V3a=45,0,55
V3b=50,0,55
V3c=55,0,55
i=1173
V3a=60,0,55
V3b=65,0,55
V3c=70,0,55
i=1176
V3a=75,0,55
V3b=80,0,55
V3c=85,0,55
i=1179
V3a=90,0,55
V3b=95,0,55
V3c=100,0,55
i=1182
V3a=105,0,55
V3b=110,0,55
V3c=-70,0,60
i=1185
V3a=-65,0,60
V3b=-60,0,60
V3c=-55,0,60
i=1188
V3a=-50,0,60
V3b=-45,0,60
V3c=-40,0,60
i=1191
V3a=-35,0,60
V3b=-30,0,60
V3c=-25,0,60
i=1194
V3a=-20,0,60
V3b=-15,0,60
V3c=-10,0,60
i=1197
V3a=-5,0,60
V3b=0,0,60
V3c=5,0,60
i=1200
V3a=10,0,60
V3b=15,0,60
V3c=20,0,60
i=1203
V3a=25,0,60
V3b=30,0,60
V3c=35,0,60
i=1206
V3a=40,0,60
V3b=45,0,60
V3c=50,0,60
i=1209
V3a=55,0,60
V3b=60,0,60
V3c=65,0,60
i=1212
V3a=70,0,60
V3b=75,0,60
V3c=80,0,60
i=1215
V3a=85,0,60
V3b=90,0,60
V3c=95,0,60
i=1218
V3a=100,0,60
V3b=105,0,60
V3c=110,0,60
i=1221
V3a=-70,0,65
V3b=-65,0,65
V3c=-60,0,65
i=1224
V3a=-55,0,65
V3b=-50,0,65
V3c=-45,0,65
i=1227
V3a=-40,0,65
V3b=-35,0,65
V3c=-30,0,65
i=1230
V3a=-25,0,65
V3b=-20,0,65
V3c=-15,0,65
i=1233
V3a=-10,0,65
V3b=-5,0,65
V3c=0,0,65
i=1236
V3a=5,0,65
V3b=10,0,65
V3c=15,0,65
i=1239
V3a=20,0,65
V3b=25,0,65
V3c=30,0,65
i=1242
V3a=35,0,65
V3b=40,0,65
V3c=45,0,65
i=1245
V3a=50,0,65
V3b=55,0,65
V3c=60,0,65
i=1248
V3a=65,0,65
V3b=70,0,65
V3c=75,0,65
i=1251
V3a=80,0,65
V3b=85,0,65
V3c=90,0,65
i=1254
V3a=95,0,65
V3b=100,0,65
V3c=105,0,65
i=1257
V3a=110,0,65
V3b=-70,0,70
V3c=-65,0,70
i=1260
V3a=-60,0,70
V3b=-55,0,70
V3c=-50,0,70
i=1263
V3a=-45,0,70
V3b=-40,0,70
V3c=-35,0,70
i=1266
V3a=-30,0,70
V3b=-25,0,70
V3c=-20,0,70
i=1269
V3a=-15,0,70
V3b=-10,0,70
V3c=-5,0,70
i=1272
V3a=0,0,70
V3b=5,0,70
V3c=10,0,70
i=1275
V3a=15,0,70
V3b=20,0,70
V3c=25,0,70
i=1278
V3a=30,0,70
V3b=35,0,70
V3c=40,0,70
i=1281
V3a=45,0,70
V3b=50,0,70
V3c=55,0,70
i=1284
V3a=60,0,70
V3b=65,0,70
V3c=70,0,70
i=1287
V3a=75,0,70
V3b=80,0,70
V3c=85,0,70
i=1290
V3a=90,0,70
V3b=95,0,70
V3c=100,0,70
i=1293
V3a=105,0,70
V3b=110,0,70
V3c=-70,0,75
i=1296
V3a=-65,0,75
V3b=-60,0,75
V3c=-55,0,75
i=1299
V3a=-50,0,75
V3b=-45,0,75
V3c=-40,0,75
i=1302
V3a=-35,0,75
V3b=-30,0,75
V3c=-25,0,75
i=1305
V3a=-20,0,75
V3b=-15,0,75
V3c=-10,0,75
i=1308
V3a=-5,0,75
V3b=0,0,75
V3c=5,0,75
i=1311
V3a=10,0,75
V3b=15,0,75
V3c=20,0,75
i=1314
V3a=25,0,75
V3b=30,0,75
V3c=35,0,75
i=1317
V3a=40,0,75
V3b=45,0,75
V3c=50,0,75
i=1320
V3a=55,0,75
V3b=60,0,75
V3c=65,0,75
i=1323
V3a=70,0,75
V3b=75,0,75
V3c=80,0,75
i=1326
V3a=85,0,75
V3b=90,0,75
V3c=95,0,75
i=1329
V3a=100,0,75
V3b=105,0,75
V3c=110,0,75
i=1332
V3a=-70,0,80
V3b=-65,0,80
V3c=-60,0,80
i=1335
V3a=-55,0,80
V3b=-50,0,80
V3c=-45,0,80
i=1338
V3a=-40,0,80
V3b=-35,0,80
V3c=-30,0,80
i=1341
V3a=-25,0,80
V3b=-20,0,80
V3c=-15,0,80
i=1344
V3a=-10,0,80
V3b=-5,0,80
V3c=0,0,80
i=1347
V3a=5,0,80
V3b=10,0,80
V3c=15,0,80
i=1350
V3a=20,0,80
V3b=25,0,80
V3c=30,0,80
i=1353
V3a=35,0,80
V3b=40,0,80
V3c=45,0,80
i=1356
V3a=50,0,80
V3b=55,0,80
V3c=60,0,80
i=1359
V3a=65,0,80
V3b=70,0,80
V3c=75,0,80
i=1362
V3a=80,0,80
V3b=85,0,80
V3c=90,0,80
i=1365
V3a=95,0,80
V3b=100,0,80
V3c=105,0,80





As you can see from the output not once does the Ray hit the planes position even though I am clearly hitting a triangle on the plane. I even set it into wireframe mode so that I only picked one triangle and not confuse it.

So the question is. Did I miss something out?

Thank you for sticking with me and reading all this. I am suspecting the problem lies in the XY point and XZ plane needing to work together but I'm not sure how that would work in this example as none of the sites I found had a plane example.

edit:
Okay found this site : http://www.3dkingdoms.com/selection.html#linetri so tried to implement his test in my test code instead to locate which triangle has been selected. Same problem, not match found. Heres the altered code now:


int DXPrimitive::PickVertex(Vector3 RayPos,Vector3 RayDir)
{
Vector3 tempV3a;
Vector3 tempV3b;
Vector3 tempV3c;
Vector3 tempNorm;
Vector3 tempIntersect;
Vector3 tempHit;
Vector3 tempTest;
bool skiptest = false;
bool hit = true;
FileStream* fs;
StreamWriter* sw;
fs = __gc new FileStream("PickVertex.txt",FileMode::CreateNew);
sw = __gc new StreamWriter(fs);
sw->WriteLine(String::Format("RayPos = {0}, RayDir = {1}",__box(RayPos),__box(RayDir)));

for (int i = 0; i < m_vertexCount-2; i+=3)
{
if (m_cvt == DXBase::CustomVertexType::NormalisedColored)
{
sw->WriteLine(String::Format("i={0}",__box(i)));
tempV3a = Vector3(m_PNCVerts.X,m_PNCVerts.Y,m_PNCVerts.Z);
tempV3b = Vector3(m_PNCVerts[i+1].X,m_PNCVerts[i+1].Y,m_PNCVerts[i+1].Z);
tempV3c = Vector3(m_PNCVerts[i+2].X,m_PNCVerts[i+2].Y,m_PNCVerts[i+2].Z);
sw->WriteLine(String::Format("V3a={0},{1},{2}",__box(tempV3a.X),__box(tempV3a.Y),__box(tempV3a.Z)));
sw->WriteLine(String::Format("V3b={0},{1},{2}",__box(tempV3b.X),__box(tempV3b.Y),__box(tempV3b.Z)));
sw->WriteLine(String::Format("V3c={0},{1},{2}",__box(tempV3c.X),__box(tempV3b.Y),__box(tempV3c.Z)));

tempNorm = Vector3::Cross(tempV3b-tempV3a,tempV3c-tempV3a);
tempNorm.Normalize();
float fDist1 = Vector3::Dot((RayPos - tempV3a),(tempNorm));
float fDist2 = Vector3::Dot((RayDir - tempV3a),(tempNorm));
sw->WriteLine(String::Format("Normal={0},Distance={1},{2}",__box(tempNorm),__box(fDist1),__box(fDist2)));

if ((fDist1 * fDist2) >= 0.0f) skiptest = true;
if (fDist1 == fDist2) skiptest = true;
if (!skiptest)
{
tempIntersect = tempV3a + (tempV3b-tempV3a) * (-fDist1/(fDist2-fDist1));
tempTest = Vector3::Cross(tempNorm,tempV3b-tempV3a);
sw->WriteLine(String::Format("Intersect={0},Test={1}",__box(tempIntersect),__box(tempTest)));

if (Vector3::Dot(tempTest,tempIntersect-tempV3a) < 0.0f) hit = false;
if (Vector3::Dot(tempTest,tempIntersect-tempV3b) < 0.0f) hit = false;
if (Vector3::Dot(tempTest,tempIntersect-tempV3c) < 0.0f) hit = false;
if (hit)
{
tempHit = tempIntersect;
sw->WriteLine(String::Format("Successful Hit={0}",__box(tempHit)));
return i;
}
}
}
}
sw->Close();
return -1;
}




The relevant routines have had their return values altered accordingly to reflect the new value. Now unless I am misunderstanding what of my values are the ones to use based on his code it seems I am never hitting the clearly hittable plane.

edit 2:
Well finally figured it out, well maybe. Had to change the code slightly but now it picks out the same triangles every time instead of different ones that I am selecting.


int DXPrimitive::PickVertex(Vector3 RayPos,Vector3 RayDir)
{
Vector3 tempV3a;
Vector3 tempV3b;
Vector3 tempV3c;
Vector3 tempNorm;
Vector3 tempIntersect;
Vector3 tempHit;
Vector3 tempTest;
bool skiptest = true;
bool hit = true;
int VertexHit;

for (int i = 0; i < m_vertexCount-2; i+=3)
{
VertexHit = -1;
if (m_cvt == DXBase::CustomVertexType::NormalisedColored)
{
tempV3a = Vector3(m_PNCVerts.X,m_PNCVerts.Y,m_PNCVerts.Z);
tempV3b = Vector3(m_PNCVerts[i+1].X,m_PNCVerts[i+1].Y,m_PNCVerts[i+1].Z);
tempV3c = Vector3(m_PNCVerts[i+2].X,m_PNCVerts[i+2].Y,m_PNCVerts[i+2].Z);

tempNorm = Vector3::Cross(tempV3b-tempV3a,tempV3c-tempV3a);
tempNorm.Normalize();

float fDist1 = Vector3::Dot((RayPos - tempV3a),(tempNorm));
float fDist2 = Vector3::Dot((RayDir - tempV3a),(tempNorm));

float DistTest = fDist1 * fDist2;

skiptest = false;
if ((fDist1 * fDist2) >= 0.0f) skiptest = true;
if (fDist1 == fDist2) skiptest = true;
if (!skiptest)
{
tempIntersect = tempV3a + (tempV3b-tempV3a) * (-fDist1/(fDist2-fDist1));

hit = true;
tempTest = Vector3::Cross(tempNorm,tempV3b-tempV3a);
if (Vector3::Dot(tempTest,tempIntersect-tempV3a) < 0.0f) hit = false;
tempTest = Vector3::Cross(tempNorm,tempV3c-tempV3b);
if (Vector3::Dot(tempTest,tempIntersect-tempV3b) < 0.0f) hit = false;
tempTest = Vector3::Cross(tempNorm,tempV3a-tempV3c);
if (Vector3::Dot(tempTest,tempIntersect-tempV3a) < 0.0f) hit = false;
if (hit)
{
tempHit = tempIntersect;
VertexHit = i;
i = m_vertexCount;
}
}
}
}
return VertexHit;
}



There are over 1300 vertexpoints in this plane and for some strange reason it insists that I am selecting either 36 or 72 even if I am not selecting anything on the grid.

Needless to say this is starting to get on my nerves.

[Edited by - Xrystal on May 30, 2006 12:39:18 PM]

Share this post


Link to post
Share on other sites
Looking at that code example link, thanks by the way, it looks like my ray generating code was almost identical and still not working. I can only assume then that my camera code is wrong .. looking like I may have to take a step back and work out whats missing from the camera code that the ray picking code needs.

edit:

Unfortunately it won't compile for me as it cannot find windows.h and neither can I for visual C++ 2005 compiling.

The unmanaged code int it is clear enough though for me to see if I can work with it with my managed code.

Share this post


Link to post
Share on other sites
finally came back to this problem and solved it,

i was testing my picking in windowed mode, then realised that the mouse co-ords didnt start at 0,0 in windowed they started at about 60 which left a little offset

but in fullscreen it worked perfectly

sny idea how i cna make the mouse co-ords range from 0,0 to screen width, height in windowed mode rather than what they currently are?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!