Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 877 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Rotating an arbitrary oriented entity #173850
12/19/07 21:00
12/19/07 21:00
Joined: Jan 2007
Posts: 221
F
Fenriswolf Offline OP
Member
Fenriswolf  Offline OP
Member
F

Joined: Jan 2007
Posts: 221
Hello,


I have scripted a simple turret that can shoot at arbitrary targets.
The turret itself can only be rotated about the Z axis (pan). Its barrel can only be rotatet about the Y axis (tilt).

The script works fine as long as the turret is located on a plane floor.
However if it is standing on a wall or a ceiling it doesn't work anymore.

I know how to rotate the turret about its local axes; what i don't know is:
How do I calculate the direction vector accordingly, so that the turret can be rotated to its target (while being arbitrary oriented)?


Any help is appreciated.

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 Offline
Expert
frazzle  Offline
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
F
Fenriswolf Offline OP
Member
Fenriswolf  Offline OP
Member
F

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: Fenriswolf] #173853
12/20/07 07:49
12/20/07 07:49
Joined: Aug 2005
Posts: 1,558
HK
V
vlau Offline
Serious User
vlau  Offline
Serious User
V

Joined: Aug 2005
Posts: 1,558
HK
Maybe try to modify the following lines :

Code:

var speed = 0.5; // play with 0.5
// first rotate the turret's body
//ang_rotate(my.pan, vector(ang(ang_to_ent.pan - my.pan),0,0));
my.pan += ang(ang_to_ent.x-my.pan) * speed * time_step;

//now rotate the barrel
//vec_set(you.pan, my.pan);
//ang_rotate(you.pan, vector(0,ang(ang_to_ent.tilt - you.tilt),0));


my.tilt += ang(ang_to_ent.y-my.tilt) * speed * time_step;


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 Offline
Expert
xXxGuitar511  Offline
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 Offline
Expert
frazzle  Offline
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 Offline
Expert
xXxGuitar511  Offline
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 Offline
Expert
frazzle  Offline
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
F
Fenriswolf Offline OP
Member
Fenriswolf  Offline OP
Member
F

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 Offline
Expert
xXxGuitar511  Offline
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
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1