Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-22-2012, 01:07 AM   PM User | #1
Scriptr
Regular Coder

 
Join Date: Oct 2011
Posts: 106
Thanks: 12
Thanked 0 Times in 0 Posts
Scriptr is an unknown quantity at this point
Rotation to slope

I am making an Asteroids-like game in OpenGL, using LWJGL. I have a box and control handling. Next step: Motion. I have it set so that left arrow rotates left and right arrow rotates right. Now I need Up arrow to go.

I have it set to go straight if it is headed straight up, down, left, or right:
Code:
public void go(){
		float r = -(this.r) % 360;
		r = r < 0 ? 360 + r : r;
		
		float dx, dy;
		
		System.out.println(r);
		if(r == 0){ y += 10; return;}
		if(r == 90){ x += 10; return;}
		if(r == 180){ y -= 10; return;}
		if(r == 270){ x -= 10; return;}
}
but now what if it is at an angle? I need to do several things:
  1. Determine slope
  2. Convert it to delta Y / delta X
  3. Find the equivalent fraction whose numerator and denominator are a and b in a pythagorean triple where c = 10 (or close)
Then I can adjust its position by those amounts

How should I approach this problem?
I am aware that slope is equal to tan(Θ), but I have no clue where to begin making it into a fraction.

I could loop through all possible fractions until I get one that is equivalent and a pythagorean triple, but (correct me if I'm wrong) that wouldn't be fast enough for use in a game (currently 20 ticks per second)
Scriptr is offline   Reply With Quote
Old 08-28-2012, 01:06 AM   PM User | #2
Scriptr
Regular Coder

 
Join Date: Oct 2011
Posts: 106
Thanks: 12
Thanked 0 Times in 0 Posts
Scriptr is an unknown quantity at this point
I continued to do research, and as my search got less and less specific, I found an example for Flash AS3 (see link). Unless this is helpful to people who come across it later, please delete this thread.
Scriptr is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:38 AM.


Advertisement
Log in to turn off these ads.