3 registered members (NewbieZorro, TipmyPip, 1 invisible),
19,045
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
I need help, I don't really know how to do this
#324473
05/21/10 01:22
05/21/10 01:22
|
Joined: Sep 2009
Posts: 84
Theil
OP
Junior Member
|
OP
Junior Member
Joined: Sep 2009
Posts: 84
|
Hi everyone, I really appreciate some help, my problem is maybe something easy but I haven't work with this kind of things yet so I don't have too much experience combining 2D with 3D vectors. My problem is this one, I have a 3D arm which I want to follow the mouse pointer since it has a crosshair bitmap, I was trying to do so but the way I was implementing works just with 3D objects, here's the code attached to the arm model: vec_set(temp.x, me.x); vec_set(temp2.x, mouse_pos); vec_sub(temp.x, temp2.x); vec_to_angle(me.tilt, temp); And here's an image of what I want to achieve: I don't have anything else to add, so thanks for reading and I hope I can find some help soon.
Last edited by Theil; 05/21/10 05:23.
|
|
|
Re: I need help, I don't really know how to do this
[Re: Theil]
#324482
05/21/10 06:35
05/21/10 06:35
|
Joined: Jan 2002
Posts: 300 Usa
Rich
Senior Member
|
Senior Member
Joined: Jan 2002
Posts: 300
Usa
|
hmmm... Maybe vec_for_screen and / or vec_to_screen may help. Check those out in the manual. Good luck.
A8 com / A7 free
|
|
|
Re: I need help, I don't really know how to do this
[Re: Theil]
#324556
05/21/10 17:55
05/21/10 17:55
|
Joined: Nov 2007
Posts: 2,568 Germany, BW, Stuttgart
MasterQ32
Expert
|
Expert
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
|
does there any 3d object exist, where you can point at? if its so, try it with this code:
action pointAtMouse()
{
VECTOR temp;
VECTOR from;
VECTOR to;
vec_set(from,vector(mouse_pos.x,mouse_pos.y,0));
vec_set(to,vector(mouse_pos.x,mouse_pos.y,10000));
vec_for_screen(from,camera);
vec_for_screen(to,camera);
if(c_trace(from,to,IGNORE_PASSENTS))
{
vec_set(temp,tar)
}
else
{
vec_set(temp,to);
}
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp);
}
|
|
|
Re: I need help, I don't really know how to do this
[Re: Theil]
#324564
05/21/10 18:33
05/21/10 18:33
|
Joined: Nov 2007
Posts: 2,568 Germany, BW, Stuttgart
MasterQ32
Expert
|
Expert
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
|
try to calculate the angle with tangens and rotate the panel with this.
var angle = atan(mouse_pos.y / mouse_pos.y);
Last edited by Richi007; 05/21/10 18:33.
|
|
|
Re: I need help, I don't really know how to do this
[Re: Theil]
#324570
05/21/10 19:33
05/21/10 19:33
|
Joined: Mar 2009
Posts: 88
Walori
Junior Member
|
Junior Member
Joined: Mar 2009
Posts: 88
|
So you're trying a arm face the crosshair (not literally ofc as the crosshair is in 2d space whereas the arm is 3d space) try below one, untested.
VECTOR* trace_to;
var trace_distance = 500;
function trace_to_crosshair(ENTITY* ent)
{
VECTOR temp;
vec_set(temp,nullvector);
vec_set(trace_to,nullvector);
while(ent)
{
//Replace mouse cursor and trace_distance with your own variables!
vec_set(trace_to,vector(mouse_cursor.x,mouse_cursor.y,trace_distance);
vec_set(temp,trace_to.x);
vec_sub(temp,ent.x);
vec_to_angle(ent.pan,temp);
wait(1);
}
return 1;
}
|
|
|
|