Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Game Mechanics / Re: !! Please help !! Java2d geometry question. on: 2008-04-09 15:10:46
Thanks for your help. I found out that it is in fact a lot simpler than I thought. By using arctan on the change in x and y I get the correct result:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
   public void calculateBearing() {
     
      updateObstacleLine();
     
      float dx = (botCentre.x - obstLoc.x);
      float dy = (botCentre.y - obstLoc.y);
     
      double thetaRadians = (StrictMath.atan2(dy,dx));
      double thetaDegrees = StrictMath.toDegrees(thetaRadians);
     
      targetAngle = thetaRadians;
     
      targetBearingVec = new Vector2f(thetaDegrees);

   }


However, I now need to work out how to decide whether to rotate CW or CCW to get to this new bearing. Many thanks for your input.
2  Game Development / Game Mechanics / !! Please help !! Java2d geometry question. on: 2008-04-08 15:55:39
Hi! I have a java2d geometry problem that I am trying to solve for a project I'm currently working on. My maths isn't great by any stretch of the imagination, so it might be true that this is a lot simpler than I am imagining. Please forgive my ignorance. I have made a quick visual representation of what I am trying to achieve (see). The scenario is as follows:

My (circular) bot has a surrounding Circle representing it's sensor range. When this circle intercepts an obstacle (also a circle) my checkCollision() method returns true. The Bot class holds the bearing (in radians) which the bot is currently travelling towards. When the bot collides with the Obstacle, I want it to call the rotate() method - this rotates the bot by a small increment each game loop - until the bot is facing in the opposite direction to the Obstacle. I create a line to join the obstacle with the bot, representing the bearing of the Obstacle. But what I really need to know is theta - the angle between the current bearing and the new bearing.

My first idea was to call rotate() until the bearing line was parallel with the obstBearing line, however I can't work out how to do that and it might cause a problem if the bot rotates clockwise instead of anti-clockwise. So it looks like I'm in for some complicated trigonometry. Any ideas(?) much appreciated. Thanks for reading this.

Here's some of my code to give an idea of how my program works:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
public double calculateBearing() {
      double newBearing = 0;
      Line hypotenuse;
      Vector2f intersection;
      double m, c, x2, x1, y2, y1, r;
     
      x1 = botCentre.x;
      y1 = botCentre.y;
      x2 = obstLoc.x;
      y2 = obstLoc.y;
      r = sensCircle.getRadius();
      m = (botCentre.y - obstLoc.y)/(botCentre.x - obstLoc.y); // gradient (or slope) of line
     c = y1 - (m * x1); // y intersection

//calculations here
     
      return newBearing;
   }

Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (3 views)
2014-08-01 19:37:19

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (27 views)
2014-07-29 18:09:19

Riven (16 views)
2014-07-29 18:08:52

Dwinin (14 views)
2014-07-29 10:59:34

E.R. Fleming (35 views)
2014-07-29 03:07:13

E.R. Fleming (13 views)
2014-07-29 03:06:25

pw (44 views)
2014-07-24 01:59:36

Riven (46 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15
Resources for WIP games
by CogWheelz
2014-08-01 18:20:17

Resources for WIP games
by CogWheelz
2014-08-01 18:19:50

List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!