1 registered members (Nymphodora),
490
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Getting the vertexes of a triangle
#387988
11/26/11 17:37
11/26/11 17:37
|
Joined: Sep 2007
Posts: 101 Luxembourg
krial057
OP
Member
|
OP
Member
Joined: Sep 2007
Posts: 101
Luxembourg
|
Hey community, I'm trying to get the Vertex numbers of the face a user clicks on. I have tried to get them with ent_buffers, here is my code:
if(c_trace (from,to, SCAN_TEXTURE|USE_POLYGON)>0)
{
CONTACT* c = ent_getvertex(hit.entity, NULL, hit.vertex);
short* trianlgeBuffer;
ent_buffers(hit.entity,0,0,NULL,&trianlgeBuffer,NULL);
short sv1=trianlgeBuffer[hit.triangle*3];
short sv2=trianlgeBuffer[hit.triangle*3+1];
short sv3=trianlgeBuffer[hit.triangle*3+2];
printf("clicked:%i / triangle vertexes:%i ; %i ; %i",(short)(int)c.vertex,sv1,sv2,sv3);
if(hit.vertex==sv1||hit.vertex==sv2||hit.vertex==sv3) printf("This should always pop up :S");
}
However the vertex numbers of the triangle are not the same as the vertex number of hit, but they are in the same range regards, Alain P.S: is here a welcome thread to present myself?
|
|
|
Re: Getting the vertexes of a triangle
[Re: krial057]
#389228
12/11/11 20:51
12/11/11 20:51
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Hi and welcome! The problem is that hit.triangle and hit.vertex start at 1, not at 0: ent_buffers(hit.entity,0,0,NULL,&trianlgeBuffer,NULL); hit.triangle--; hit.vertex--; short sv1= ...
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Getting the vertexes of a triangle
[Re: Superku]
#389280
12/12/11 18:04
12/12/11 18:04
|
Joined: Sep 2007
Posts: 101 Luxembourg
krial057
OP
Member
|
OP
Member
Joined: Sep 2007
Posts: 101
Luxembourg
|
Thank you, it works I spend so many hours on this problem, and that -- was the whole thing xD Just an other question out of curiosity (not important for my project, but something i don't understand): Is 3dgs cheating with c_trace and getting the nearest vertex? If I have a face and i trace it with c_trace, the hit.vertex index is always the same, even if I trace nearer on an other vertex of that face
|
|
|
Re: Getting the vertexes of a triangle
[Re: krial057]
#389283
12/12/11 18:15
12/12/11 18:15
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Had to test the code myself to find the problem! Yes it seems like hit.vertex is always the first vertex of the triangle, so you have to calculate it yourself: D3DVERTEX* vbuffer; ent_buffers(hit.entity,0,0,&vbuffer,&triangleBuffer,NULL); ... vec_to_ent(target,hit.entity); var max_dist = 999,j,k; for(i = 0; i < 3; i++) { j = vec_dist(target,(vector(vbuffer[triangleBuffer[hit.triangle*3+i]].x,vbuffer[triangleBuffer[hit.triangle*3+i]].z,vbuffer[triangleBuffer[hit.triangle*3+i]].y)); if(j < max_dist) { max_dist = j; k = i; } } Now k should be your closest vertex!
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
|