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.

AppGameKit Classic Chat / Can you simplify my trigonometry?

Author
Message
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th Dec 2011 14:32 Edited at: 19th Dec 2011 14:32
Here's my issue:



In the image, I know that my distance from the centre of the screen is 100 units.

From the device accelerometer I know that x = "0.4" and y = "0.5"

I need to convert the x and y ratios to units so that I can place my graphic 100 units from the centre, in the direction I am tipping the device.

This is my code which works, but I'm sure it could be so much neater. H# is the hypotenuse of the triangle, x# and y# are my final values in units. My theory is that I have to convert 100 units to the same scale as the x/y ratios, so that I can then multiply the ratios out to units.



Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 19th Dec 2011 15:54 Edited at: 19th Dec 2011 15:55
You could use "GetDirectionAngle()" to get the angle and calculate a value for x and y;


EDIT: Also you could use a lookup table for sin and cos...

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 19th Dec 2011 16:40
Quote: "You could use "GetDirectionAngle()" to get the angle and calculate a value for x and y;"


doh! It sounds so obvious now you've said it

Quote: "Also you could use a lookup table for sin and cos..."

I have considered it, I often do this in DBP. I'm not too use on the memory requirements for AppGameKit, and whether I'm using memory that is at a cost to the overall performance. I suppose it's only going to be around 1.5K per table (360 degrees * 4 bytes)

Login to post a reply

Server time is: 2024-11-22 20:50:24
Your offset time is: 2024-11-22 20:50:24