Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

3 Dimensional Chat / Tricky Trigonometrical stuff

Author
Message
WaNnAbE
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location:
Posted: 22nd Nov 2003 14:28
Well, I've got some code that makes a sphere out of little cubes. It's going to be the main character for a (fairly abstract) game I'm making. Has anyone here played Rez? I want the sphere to roll as you move. Not just for the whole object to roll, but for the individual cubes to stay upright, but move so that the overall impression is of the sphere rolling, if that makes sense. So I've got it to roll one way (forwards) but I can't manage sideways. Any help?



[A witty, geek culture comment goes here]
QuothTheRaven
22
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 23rd Nov 2003 00:31
I understand what you're saying, and it sounds extremely hard. If you can get all of the cubes to revolve around the center point, then what would be easiest is to just use the point object command and point each cube at an invisible object above the ball.

As for getting the cubes to revolve around a center point, there's probably some algorithm somewhere to change the rotation axis of an object. But I don't know more than that...

Evil Noodle
22
Years of Service
User Offline
Joined: 28th Apr 2003
Location:
Posted: 23rd Nov 2003 03:01
i used the following in a prog i was doing. A collision box was to be rotated around the enemy ,in the relveant angle to where he was facing.

in my case zp/xp is the player position ze/ze is the enemy

angle#=atanfull((zp#-ze#),(xe#-xp#))

this works out the y angle between enemy and player
in a seperate function i then used:

yrotate object enemy,int(losangle#)
yrotate object col_box,int(losangle#)
col_boxz=sin(int(angle#))*(0.5*view_distance)
col_boxx=cos(int(angle#))*(0.5*view_distance)

this rotates the box to enemy angle and calculates the distances from the enemy that the collision box should be. I dont know how relevent to you this is but i felt like waffling on.
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 23rd Nov 2003 03:25
Here's your answer (took me half an hour at 1 oclock in the morning, so I hope you are grateful!!!!)




Boo!
Dimension
21
Years of Service
User Offline
Joined: 23rd Nov 2003
Location:
Posted: 23rd Nov 2003 12:23
Here is a formula for rotating points around a position

theta > an angle from left to right
phi > an angle from up to down

position of orgin where you want to rotate
XP > x position
YP > y position
ZP > z position

Fx = (-x * sin(theta) + y * cos(theta)) + XP
Fy = (-x * cos(theta) * sin(phi) - y * sin(theta) * sin(phi) - z * cos(phi)) + YP
Fz = (-x * cos(theta) * cos(phi) - y * sin(theta) * cos(phi) + z * sin(phi)) + ZP

I think that will work.

This can also be used to create a 3D engine but theres a little more to it.
WaNnAbE
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location:
Posted: 23rd Nov 2003 13:47
Wow, thanks spooky but I'm afraid that I'm using DBclassic, so that's very little good to me. Thanks all the same. Morpheus, I'm about to have a look at that, and I should be able to integrate it into my program fairly easily by replacing xp, yp and zp with my character co-ordinates. So yeah, thanks.

[A witty, geek culture comment goes here]
WaNnAbE
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location:
Posted: 27th Nov 2003 19:36
Hmm... After a few days of trying I can't figure out your thingy morpheus. It is ok for moving sideways, but it does something extremely weird if I try to move it up or down. So yeah, do you think you could take a look at it and check whether one of us has made a mistake?

Code attached.

[A witty, geek culture comment goes here]

Login to post a reply

Server time is: 2025-06-27 11:58:09
Your offset time is: 2025-06-27 11:58:09