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.

DarkBASIC Discussion / Object angle issues

Author
Message
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 19th May 2010 22:50
I am working on a project that will eventually use raycasting for collision, since sparky's doesn't seem to like sliding collision. My solution has been to cast multiple rays from each face to detect for collision at different points.

This program was a test one that I wrote that should place spheres at each point for the ray (a + on the face). My problem is that when turning the object, the spheres will turn with the object for a little bit, then rotate the wrong way until they hit the right point again (run the program if you are confused)


Here is the code:



Notes on the code:
-I was lazy and decided to store the initial offset values in one number using RGB (I didn't feel like 3 lines of code for each point)
-The "center" point for the rgb values is (100,100,100). I did this since you can't put negative values in. The solution was just to subtract 100 from the rgb values (so instead of -30, I put 70 and later subtract 100 from it).
-The Xdiff# and Zdiff# equations that have the xcos-zsin and xsin+zcos come from a rotation matrix:
|cos -sin|
|sin cos| Which gets multiplied by the normal offsets to find the new ones. If you aren't familiar with the math, assume its right.

Thanks

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 19th May 2010 23:06
Alright, so I kinda answered my own question- the problem was with the TURN OBJECT commands, which seems to cycle between +90 and -90 (not sure how that works). I replaced it with yrotate and now I am getting everything to rotate together, but in opposite directions.


New code:


Notes on things I have tried:
-I switched the equations for xdiff# and zdiff# and it made it rotate correctly, but the offsets (obviously) were flipped (so the spheres were no longer on the face.

-I switched the sin's to cos's and cos's to sin's and I got the same result

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 19th May 2010 23:13
Fixed it with fuzzy math.

multiplied the zdiff# equation by -1. Don't really know why it worked. Any ideas?

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 22nd May 2010 02:03
I think the reason why you have to multiple the zdiff# equation by is probably due to how angles are measured on the XZ plane (however, the fact that you didn't have to do this with xdiff# could also mean I'm completely wrong).

However, angles are meassured anticlockwise from the positive z axis (which I'm guessing you probably already know). So when using trigonemetry, you can't just substitute Y with Z because:

Opposite = difference in X
Adjacent = difference in Z

In normal cartesean coordinates:

Opposite = difference in Y
Adjacent = difference in X

I've been doing a lot of my own maths collision recently and this has caused no end of confusion and I've had to use plently of "fuzzy" maths myself (thank you to latch for hepling to clarify the problem on one of my threads).

If you look at my thread:

http://forum.thegamecreators.com/?m=forum_view&t=167811&b=10

the pdf download goes through the maths I used but the thing you'll want to note is the axis symbol on all the diagrams that shows the direction the angles are measured in. Page six also makes a comparison to how the equations look when dealing with the XZ axis and normal cartesian coordinates (although I'm not using any trig).

Hope this helps.

Login to post a reply

Server time is: 2024-04-24 06:06:54
Your offset time is: 2024-04-24 06:06:54