reflecting a laser from wall

Posted By: Rackscha

reflecting a laser from wall - 09/28/12 18:47

Hi,
seems i havent understood something correctly.

Ok, imagine we have a laser for a weapon i want to reflect from walls.

first, i calculate start/endvec for my laser.
do the trace
if i hit something:
i substract start from endvec(to get the direction, saved in BVec)
vec_to_angle for hit.nx
and rotate my BVec by the angle, add hit.x and trace again from hit.x to BVec.

Okay but the reflection seems to be wrong(as a laser hiting a surface isnt reflected straight back)

mh, maybe someone has an idea?

Greetings
Rackscha
Posted By: Ch40zzC0d3r

Re: reflecting a laser from wall - 09/28/12 19:00

you could use bounce variable of 3DGS, there are better ways, but its a start^^
Posted By: Rackscha

Re: reflecting a laser from wall - 09/28/12 19:15

bounce is not used on c_trace
Posted By: lostclimate

Re: reflecting a laser from wall - 09/28/12 20:28

add to the reflect vector an inverse of the difference between the normal and the initial vector?
Posted By: Rackscha

Re: reflecting a laser from wall - 09/28/12 21:31

is the normalvector normalized between -1 to 1
if its normalized, a difference is not directly possible, right?
Posted By: Superku

Re: reflecting a laser from wall - 09/28/12 22:36

trace -> if hit, scale normal vector with -2*vec_dot(dir,normal), add normal vector to dir (and add dir to your target vector for the new trace target location). You can search wikipedia ("reflection") for details on this formula.
Posted By: Rackscha

Re: reflecting a laser from wall - 09/28/12 23:49

thanks superku.
But i noticed that bounce is set in c_trace, too.
Now it seems to work.

Code:
vec_to_angle(LAng, bounce);
					vec_set(BVec, vector(200, 0, 0));
					vec_rotate(BVec, LAng);
					vec_add(BVec, hit.x);

© 2024 lite-C Forums