[solved]get triangle vertices by hit.triangle?

Posted By: tagimbul

[solved]get triangle vertices by hit.triangle? - 12/25/19 23:38

hello laugh

i try to read the vertices of a face,
how i can do this with hit.triangle and ent_getvertex() ?

greets tom
Posted By: tagimbul

Re: get triangle vertices by hit.triangle? - 12/26/19 03:35

i have it laugh
Code
ent_buffers(ent_level,0,0,&vbuffer,&ibuffer,NULL) ;	
v1.x = vbuffer[ibuffer[3*hit.triangle  ] ].x;
v1.y = vbuffer[ibuffer[3*hit.triangle  ] ].z;
v1.z = vbuffer[ibuffer[3*hit.triangle ]  ].y;


now i have the problem to convert the triangels to a normal vector tongue
Posted By: txesmi

Re: get triangle vertices by hit.triangle? - 12/26/19 15:12

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.

Code
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!
Posted By: tagimbul

Re: get triangle vertices by hit.triangle? - 12/26/19 21:11

hey thx
i have found a other way

Code
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 ^^"
Posted By: txesmi

Re: get triangle vertices by hit.triangle? - 12/26/19 22:35

Code
	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 ;


well, that is how cross product of 3D vectors is computed wink
© 2024 lite-C Forums