Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, TipmyPip, Edgar_Herrera), 804 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 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: 245
PA
Garrettwademan Offline OP
Member
Garrettwademan  Offline 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

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,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
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: 245
PA
Garrettwademan Offline OP
Member
Garrettwademan  Offline OP
Member

Joined: Jan 2006
Posts: 245
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: 245
PA
Garrettwademan Offline OP
Member
Garrettwademan  Offline OP
Member

Joined: Jan 2006
Posts: 245
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,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
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: 245
PA
Garrettwademan Offline OP
Member
Garrettwademan  Offline 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.

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

Joined: Jan 2006
Posts: 245
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,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
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.

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