0 registered members (),
1,089
guests, and 10
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Rotating an arbitrary oriented entity
[Re: Fenriswolf]
#173851
12/19/07 21:24
12/19/07 21:24
|
Joined: Mar 2006
Posts: 2,758 Antwerp,Belgium
frazzle
Expert
|
Expert
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
|
Maybe you could post the code you created for turning the turret around his own axis combined with the rotation part of the turret relative to the target. The error could be occuring within the code for turning the model around his own axis, you never know Thanks in progress Frazzle
Antec® Case Intel® X58 Chipset Intel® i7 975 Quad Core 8 GB RAM DDR3 SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB NVIDIA® GeForce GTX 295 Memory 1795GB
|
|
|
Re: Rotating an arbitrary oriented entity
[Re: frazzle]
#173852
12/19/07 22:39
12/19/07 22:39
|
Joined: Jan 2007
Posts: 221
Fenriswolf
OP
Member
|
OP
Member
Joined: Jan 2007
Posts: 221
|
Here is the code: Code:
define barrel_handle, skill1;
action ent_turret { my.barrel_handle = handle(ent_create("turret_barrel.mdl", my.x, NULL)); while(my) { you = ptr_for_handle(my.barrel_handle); var vec_to_ent[3]; var ang_to_ent[3]; // get the direction vector turret->camera and its angles vec_diff(vec_to_ent, camera.x, my.x); vec_to_angle(ang_to_ent, vec_to_ent); // first rotate the turret's body ang_rotate(my.pan, vector(ang(ang_to_ent.pan - my.pan),0,0)); // now rotate the barrel vec_set(you.pan, my.pan); ang_rotate(you.pan, vector(0,ang(ang_to_ent.tilt - you.tilt),0)); wait(1); } }
As you can see, the calculations of the code above will not work with arbitrary orientations. However, I have no idea what has to be changed to get it working.
|
|
|
Re: Rotating an arbitrary oriented entity
[Re: vlau]
#173854
12/20/07 13:40
12/20/07 13:40
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
..alright, I've had this problem as well, but I don't think I ever fixed it Basically, what you have to do is convert the angles from world space to object space (we already knew this). You do that by rotating the angle by the inverse of the objects angle... With vectors, this is really easy. But with angles... not so much. Here's as example using a vector: Code:
Function iRotate(&_vec, &_ang) { vec_set(temp, _ang); // Store the angle in temp vec_inverse(temp); // Invert the angle vec_rotate(_vec, temp); // Rotate the vector }
You can either try rotating the offset vector for the target before getting the direction, or, apply the same concept to the direction after you've found it. Hope I explained this well
xXxGuitar511 - Programmer
|
|
|
Re: Rotating an arbitrary oriented entity
[Re: xXxGuitar511]
#173855
12/20/07 15:24
12/20/07 15:24
|
Joined: Mar 2006
Posts: 2,758 Antwerp,Belgium
frazzle
Expert
|
Expert
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
|
Well in theory, this is what Guitar proposed: Code:
vec_set(temp,vector(entity.pan,0,0)); // Store the angle in temp vec_inverse(temp); // Invert the angle ang_rotate(entity.pan,temp); // Rotate the angle
Ang_add wouldn't help since it's used for adjusting angles relative to the world axis AFAIK Cheers Frazzle
Antec® Case Intel® X58 Chipset Intel® i7 975 Quad Core 8 GB RAM DDR3 SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB NVIDIA® GeForce GTX 295 Memory 1795GB
|
|
|
Re: Rotating an arbitrary oriented entity
[Re: frazzle]
#173856
12/20/07 18:24
12/20/07 18:24
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
...IDK, I haven't tried it out yet (I'm hoping I'll have time soon), but I think if you rotate the offset first, then it will work better. Hard to explain: var offset[3]; vec_diff(offset, you.x, my.x); vec_iRotate(offset, my.pan); ...the offset variable should now have the "local difference", instead of world. So now: vec_to_angle(temp, offset); ...temp now holds the angle it should point in relative to the model. c_rotate(..., temp, ... + USE_AXISR); ...I don't know, something like that. I never really use c_rotate(). Of course all of this is just theory, and I'll just have to test it later
xXxGuitar511 - Programmer
|
|
|
Re: Rotating an arbitrary oriented entity
[Re: xXxGuitar511]
#173857
12/20/07 19:32
12/20/07 19:32
|
Joined: Mar 2006
Posts: 2,758 Antwerp,Belgium
frazzle
Expert
|
Expert
Joined: Mar 2006
Posts: 2,758
Antwerp,Belgium
|
Seems logic but I don't get why you set you.x if you need to calculate the origin of my ?? Btw, didn't you mean : Code:
vec_rotate(offset, my.pan);
Thanks in progress Frazzle
Antec® Case Intel® X58 Chipset Intel® i7 975 Quad Core 8 GB RAM DDR3 SSD OCZ®-VERTEX2 3.5 x4 ; HD 600 GB NVIDIA® GeForce GTX 295 Memory 1795GB
|
|
|
Re: Rotating an arbitrary oriented entity
[Re: frazzle]
#173858
12/21/07 02:03
12/21/07 02:03
|
Joined: Jan 2007
Posts: 221
Fenriswolf
OP
Member
|
OP
Member
Joined: Jan 2007
Posts: 221
|
Thanks, I have tried to implement your suggestions into my code. However I didn't have much success in doing so. Standing on a plane the turret is still working fine. But when its angles are changed (e.g. tilt or roll) it aims at a wrong location. Nevertheless I think this is the right approach. This is the code: Code:
define barrel_handle, skill1;
action ent_turret { my.barrel_handle = handle(ent_create("turret_barrel.mdl", my.x, NULL)); while(my) { you = ptr_for_handle(my.barrel_handle); var vec_to_ent[3]; var ang_to_ent[3];
vec_diff(vec_to_ent, camera.x, my.x); // direction vector vec_set(temp, my.pan); // Store the angle in temp vec_inverse(temp); // Invert the angle vec_rotate(vec_to_ent, temp); // Rotate the vector vec_to_angle(ang_to_ent, vec_to_ent); // angle of direction vector
// first rotate the turret's body ang_rotate(my.pan, vector(ang_to_ent.pan,0,0)); // now rotate the barrel vec_set(you.pan, my.pan); ang_rotate(you.pan, vector(0,ang_to_ent.tilt,0)); wait(1); } }
|
|
|
Re: Rotating an arbitrary oriented entity
[Re: Fenriswolf]
#173859
12/21/07 15:52
12/21/07 15:52
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
FenrisWolf has it right. Apparently I was wrong though. As soon as I find some time, I'll test it out...
xXxGuitar511 - Programmer
|
|
|
|