Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Nymphodora), 490 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Getting the vertexes of a triangle #387988
11/26/11 17:37
11/26/11 17:37
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline OP
Member
krial057  Offline OP
Member
K

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:

Php 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 confused

regards, Alain smile

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 Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Hi and welcome! wink
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
K
krial057 Offline OP
Member
krial057  Offline OP
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
Thank you, it works grin
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 tongue

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 Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Had to test the code myself to find the problem! wink
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
Re: Getting the vertexes of a triangle [Re: Superku] #389285
12/12/11 18:52
12/12/11 18:52
Joined: Sep 2007
Posts: 101
Luxembourg
K
krial057 Offline OP
Member
krial057  Offline OP
Member
K

Joined: Sep 2007
Posts: 101
Luxembourg
Thank you, nice snippet grin

Greetings from Luxembourg wink


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1