|
Need a Math Pro (Parent / Child Rotation and XY coords)
#475697
01/04/19 03:01
01/04/19 03:01
|
Joined: Jan 2006
Posts: 245 PA
Garrettwademan
OP
Member
|
OP
Member
Joined: Jan 2006
Posts: 245
PA
|
Okay guys, I am really sorry for this question, it seems so basic but I can't seem to get it. What I am trying to do is make a parent model (in this case the Computer Case) and child models (like CPU, RAM, Connectors) rotate in synconry yet keep their reletive X and Y positions to the computer case. Here is a video of what I have now, and here is the code I am using to do it. Is it because each model isn't aligned in its own axis in MED? Any help is greatly appreciated. Its close, but not where it should be as it rotates. YouTube Rotate Demo Current
//my is each object such as CPU, RAM, Hard Drive, Circuit Board
//arcade_Case is the Parent
//varLocDifX is the offset of the my model, relative to the arcade_Case
varLocDifX = my.x - arcade_Case.x;
varLocDifY = my.y - arcade_Case.y;
varLocDifZ = my.z - arcade_Case.z;
my.pan = arcade_Case.pan;
my.x = arcade_Case.x + varLocDifX * cos(arcade_Case.pan + 90);
my.y = arcade_Case.y + varLocDifY * sin(arcade_Case.pan + 90);
my.z = arcade_Case.z + varLocDifZ;
Last edited by Garrettwademan; 01/04/19 03:05.
|
|
|
Re: Need a Math Pro (Parent / Child Rotation and XY coords)
[Re: Garrettwademan]
#475702
01/04/19 09:30
01/04/19 09:30
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Hi, a 2d vector rotation is computed as follows
x1 = x * cos - y * sin;
y1 = x * sin + y * cos;
Anyway, the computation of the offset vector should not be performed each frame. Otherway it will continuously lose a little length caused by the accuracy limits of the variables.
vec_diff(my.skill1, my.x, entParent.x); // save the offset vector into three skills
while(1) {
vec_set(my.x, my.skill1);
vec_rotate(my.x, entParent.pan);
vec_add(my.x, entParent.x);
vec_set(my.pan, entParent.pan);
wait(1);
}
Salud!
|
|
|
Re: Need a Math Pro (Parent / Child Rotation and XY coords)
[Re: Garrettwademan]
#477501
07/02/19 18:46
07/02/19 18:46
|
Joined: Jan 2006
Posts: 245 PA
Garrettwademan
OP
Member
|
OP
Member
Joined: Jan 2006
Posts: 245
PA
|
Hello again. I added a bit of complexity to this code where parts can have offsets (if a tab or switch is flipped it adds to the pan/tilt/roll). So imagine a PC Desktop that has parts in it. As the user moves the PC desktop around the game, the internal objects follow with it. I added some code so that certain tabs / switches can be adjusted, but still has to follow the "arcade_Case" but with the pan/tilt/roll offset. When I run this code below, it seems to semi work. When any data is in the StartxxxOffset the items react, but only from a world perspective, not based upon the object access. I attempted to use ang_add() but it didn't give me the results I was looking for. This example only works if the PC Desktop is in the original position at the start of the game, otherwise the tabs / switches get out of sync. //me = tab or switch that follows arcade_Case vec_set(my.x, my.skill1); vec_rotate(my.x, arcade_Case.pan); vec_add(my.x, arcade_Case.x); vec_set(my.pan, arcade_Case.pan); my.pan += my.StartPanOffset; my.tilt += my.StartTiltOffset; my.roll += my.StartRollOffset; I am going to keep working on it but open for some help.
Last edited by Garrettwademan; 07/02/19 19:03.
|
|
|
Re: Need a Math Pro (Parent / Child Rotation and XY coords)
[Re: Garrettwademan]
#477504
07/03/19 07:03
07/03/19 07:03
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
Hi, yes, it is fine. Euler angles are not euclidean and can't be opperated raw. That is the reason of the existence of 'ang_rotate'. As addition, in the case the backup angles are contiguous and correctly sorted you don't need to build a temporary vector. The use of the first member as reference is enough. Another little thing is that, conceptually, the added rotation is the case's one, but it doesn't really matter.
vec_set(my.pan, my.StartPanOffset);
ang_rotate(my.pan, arcade_Case.pan);
Salud!
|
|
|
|