|
[solved]get triangle vertices by hit.triangle?
#478819
12/25/19 23:38
12/25/19 23:38
|
Joined: Jun 2010
Posts: 212
tagimbul
OP
Member
|
OP
Member
Joined: Jun 2010
Posts: 212
|
hello i try to read the vertices of a face, how i can do this with hit.triangle and ent_getvertex() ? greets tom
Last edited by tagimbul; 12/28/19 13:27.
|
|
|
Re: get triangle vertices by hit.triangle?
[Re: tagimbul]
#478822
12/26/19 15:12
12/26/19 15:12
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Hi, the normal of a triangle can be computed by the cross product of two of its edges. I mean, on an ABC triangle, AB x AC. The result may need to be normalized. As a unasked tip, It is always good to not to repeat the same operation. It is faster to get a pointer to the D3DVERTEX struct for each vertex.
ent_buffers(ent_level, 0, 0, &vbuffer ,&ibuffer, NULL) ;
short *ibT = ibuffer + (int)hit.triangle * 3;
D3DVERTEX *vbT = vbuffer + *ibT;
v1.x = vbT->x;
v1.y = vbT->z;
v1.z = vbT->y:
vbT = vbuffer + *(++ibT);
v2.x = vbT->x;
v2.y = vbT->z;
v2.z = vbT->y:
vbT = vbuffer + *(++ibT);
v3.x = vbT->x;
v3.y = vbT->z;
v3.z = vbT->y:
vec_diff(e1, v2, v1);
vec_diff(e2, v3, v1);
vec_cross(n0, e1, e2);
vec_normalize(n0, 1);
Salud!
|
|
|
Re: get triangle vertices by hit.triangle?
[Re: tagimbul]
#478823
12/26/19 21:11
12/26/19 21:11
|
Joined: Jun 2010
Posts: 212
tagimbul
OP
Member
|
OP
Member
Joined: Jun 2010
Posts: 212
|
hey thx i have found a other way function Triangle_to_normal( VECTOR* n, VECTOR* v1, VECTOR* v2, VECTOR *v3)
{
VECTOR A,B;
vec_set (A,vec_sub (v2, v1 ));
vec_set (B,vec_sub (v3, v1 ));
n.x = A.y * B.z - A.z * B.y ;
n.y = A.x * B.z - A.z * B.x ;
n.z = A.x * B.y - A.y * B.x ;
vec_normalize(n.x,1);
} i dont know why but it works too ^^"
|
|
|
|