Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (797)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (864)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Radar for 3D Space Games  (Read 3875 times)
0 Members and 1 Guest are viewing this topic.
Offline Archive
« Posted 2017-05-28 22:12:34 »

I found creating a radar for a 6DOF game quite difficult and there were few resources that I could find online that gave me an idea of what to do, so I'm posting this here in hopes that someone will find this useful.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
   private void renderRadar(C3DVideo v) {
      int radius = 75;
      float sensitivity = 100; // the higher the sensitivity, the smoother the rotations are of the dots being drawn on the radar
      float sens_rad = radius * sensitivity;
      int dotRadius = 2;
      int xl = (mode.getWidth() / 2) - 200; // arbitrary circle drawing positions, you can put these where you'd like
      int yl = (mode.getHeight() / 2) + 120; // ^

      v.drawCircle(xl, yl, radius, 0xffffff); // draw circle at xl, yl with given radius and a white color

      v.drawCircle(xl - dotRadius, yl - dotRadius, dotRadius, 0x00ff00);
     
      // the following three lines of code should be modified to create no garbage, but this is up to you.
      float[] ps = new float[] { player.pos_x, player.pos_y, player.pos_z }; // put player position (x,y,z) into float array
      fPlane plt = new fPlane(ps, player.tangent.toArray()); // new plane, 'ps' is the point on the plane, tangent is  normal.
      fPlane plb = new fPlane(ps, player.binormal.toArray()); // new plane, 'ps' is the point on the plane, binormal is normal.
      // tangent vector is the 'forward' vector of the player, and the binormal is the 'left/right' vector of the player
      for (int i = 0; i < targets.size(); i++) {
         Entity e = targets.get(i);
         dotRadius = (int) e.radius / 8; // optional, but this line creates dots on the radar that are scaled so that they reflect the radius of the enemies
         float d1 = plb.pointPlaneDistance(e.pos_x, e.pos_y, e.pos_z); // find distance from entity's position to the binormal plane.
         if (d1 > sens_rad) {
            d1 = sens_rad;
         }
         if (d1 < -sens_rad) {
            d1 = -sens_rad;
         }
         float d2 = plt.pointPlaneDistance(e.pos_x, e.pos_y, e.pos_z); // find distance from entity's position to the tangent plane.
         if (d2 > sens_rad) {
            d2 = sens_rad;
         }
         if (d2 < -sens_rad) {
            d2 = -sens_rad;
         }
         double xc = d1 / sensitivity;
         double yc = -d2 / sensitivity; // negate the y coordinate because of window graphics
         double mag = Math.sqrt(xc * xc + yc * yc);
         // Scale vector to meet the radius if the magnitude of the vector is larger than the radius
         if (mag > radius) {
            xc  /= mag;
            yc /= mag;
            xc *= radius;
            yc *= radius;
         }
         v.drawCircle(xl + (int) xc - dotRadius, yl + (int) yc - dotRadius, dotRadius, 0xff0000); // draw entity dot on radar
      }
   }


Picture of it in game

Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (3656 views)
2018-11-16 13:46:03

hadezbladez (1301 views)
2018-11-16 13:41:33

hadezbladez (3664 views)
2018-11-16 13:35:35

hadezbladez (700 views)
2018-11-16 13:32:03

EgonOlsen (4006 views)
2018-06-10 19:43:48

EgonOlsen (4534 views)
2018-06-10 19:43:44

EgonOlsen (2694 views)
2018-06-10 19:43:20

DesertCoockie (3552 views)
2018-05-13 18:23:11

nelsongames (3709 views)
2018-04-24 18:15:36

nelsongames (4733 views)
2018-04-24 18:14:32
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
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!