c_trace and view entity

Posted By: GameScore

c_trace and view entity - 07/11/11 19:12

hi,
is it possible to start a c_trace from a view entity?

how can i do that?
Posted By: Walori

Re: c_trace and view entity - 07/11/11 19:26

It'd be something like this:

Code:
ENTITY * ent = some_entity;
function trace()
{

   var distance_from_camera = 0;
   VECTOR mouse_to_world;
   vec_set(mouse_to_world,vector(ent.x,ent.y,distance_from_camera));
   vec_for_screen (mouse_to_world, camera);

   c_trace(mouse_to_world,vec_to_somewhere,IGNORE_ME);

}


Posted By: GameScore

Re: c_trace and view entity - 07/11/11 20:15

thnx,
but no solution
it doesnt work

i want to start a c_trace from a view entity
but the c_trace starts in the middle of the lvl

look here is the code i use

vec_set(trace_coords.x, vector(1500, 0, 0));
vec_rotate(trace_coords.x, laser_gun.pan);
vec_add(trace_coords.x, laser_gun.x);
if (c_trace(laser_gun.x, trace_coords.x, IGNORE_ME ) > 0) // hit something?
{
draw_line3d(my.x,NULL,100);
draw_line3d(my.x,COLOR_RED,100);
draw_line3d(target.x,COLOR_RED,100);
draw_point3d(target.x,COLOR_RED,100,3);
}

maybe i need to use vec_for_screen
but i do not know how
Posted By: Myrkling

Re: c_trace and view entity - 07/11/11 20:58

vec_for_screen is used to convert screen coordinates into world coordinates. However, as view entities are located neither in sceen space nor in world space but in view space, vec_for_screen alone is not enough: Before using vec_for_screen you have to use rel_to_screen to convert the view entity's coordinates into screen coordinates.

So just add a rel_to_sceen to Walori's code. This should do the trick.
Posted By: GameScore

Re: c_trace and view entity - 07/12/11 15:43

i was trying but i find no solution
Posted By: bart_the_13th

Re: c_trace and view entity - 07/13/11 08:20

The view entity is inside the camera, so you can use
Code:
c_trace(camera.x, trace_coords.x, IGNORE_ME )



[EDIT]
in case you want to have 'offset' from the lasergun.x
Code:
VECTOR temp;
...
vec_set(temp.x, lasergun.x);
vec_rotate(temp.x,camera.pan);
c_trace(vec_add(camera.x, temp.x), trace_coords.x, IGNORE_ME );



Warning: the code is not tested
Posted By: GameScore

Re: c_trace and view entity - 07/17/11 18:54

i got it tnx
© 2024 lite-C Forums