Gamestudio Links
Zorro Links
Newest Posts
Gracefully closing a panel
by Zheka. 07/17/19 15:02
MaxDD in %
by Zheka. 07/17/19 14:51
New Zorro version 2.15
by jcl. 07/17/19 12:21
Issues with converting .csv to .t6
by jcl. 07/16/19 14:46
IG plugin initial release
by YG8. 07/16/19 10:02
First Steps for backtesting with ASCII data
by Charttrader. 07/16/19 08:50
Beginners Workshop
by jcl. 07/15/19 06:29
Dukascopy plugin (yet another version)
by dh85. 07/15/19 05:03
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
12 registered members (jyd, kvm, Peeyotch, Grat, AndrewAMD, FLD, TradingMax, Quad, Matt_Aufderheide, 1 invisible), 705 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Charttrader, bjomu, catharticlapse, carmyss121, Evox
18255 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
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: 244
PA
Garrettwademan Offline OP
Member
Garrettwademan  Offline OP
Member

Joined: Jan 2006
Posts: 244
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

Code:
//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.

Current Project: Computer Repair Simulator
https://www.computer-repair-simulator.com
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,234
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,234
Hiporope and its pain
Hi,
a 2d vector rotation is computed as follows

Code:
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.

Code:
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: txesmi] #475720
01/05/19 01:42
01/05/19 01:42
Joined: Jan 2006
Posts: 244
PA
Garrettwademan Offline OP
Member
Garrettwademan  Offline OP
Member

Joined: Jan 2006
Posts: 244
PA
Yea, that did the trick, amazing. Thank you! I am going to study more on these because I think this will help me with a bunch of other stuff too.


Current Project: Computer Repair Simulator
https://www.computer-repair-simulator.com
Re: Need a Math Pro (Parent / Child Rotation and XY coords) [Re: txesmi] #475760
01/07/19 06:08
01/07/19 06:08
Joined: Jan 2006
Posts: 244
PA
Garrettwademan Offline OP
Member
Garrettwademan  Offline OP
Member

Joined: Jan 2006
Posts: 244
PA
I was able to use what you had and build upon it. You were very helpful. Here is a video of it all working perfectly now.

YouTube Demo Video


Current Project: Computer Repair Simulator
https://www.computer-repair-simulator.com
Re: Need a Math Pro (Parent / Child Rotation and XY coords) [Re: Garrettwademan] #475761
01/07/19 09:08
01/07/19 09:08
Joined: Jun 2007
Posts: 1,234
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,234
Hiporope and its pain
Congratulations! laugh

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: 244
PA
Garrettwademan Offline OP
Member
Garrettwademan  Offline OP
Member

Joined: Jan 2006
Posts: 244
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.

[Linked Image]
[Linked Image]

Last edited by Garrettwademan; 07/02/19 19:03.

Current Project: Computer Repair Simulator
https://www.computer-repair-simulator.com
Re: Need a Math Pro (Parent / Child Rotation and XY coords) [Re: Garrettwademan] #477502
07/02/19 19:16
07/02/19 19:16
Joined: Jan 2006
Posts: 244
PA
Garrettwademan Offline OP
Member
Garrettwademan  Offline OP
Member

Joined: Jan 2006
Posts: 244
PA
I actually think I got it, but not confident it is the best solution.

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);
ang_rotate(my.pan, vector(my.StartPanOffset, my.StartTiltOffset, my.StartRollOffset));


Current Project: Computer Repair Simulator
https://www.computer-repair-simulator.com
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,234
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,234
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.

Code
vec_set(my.pan, my.StartPanOffset);
ang_rotate(my.pan, arcade_Case.pan);


Salud!


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