Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Trianglearray  (Read 691 times)
0 Members and 1 Guest are viewing this topic.
Offline rmdire

Junior Member





« Posted 2004-04-19 07:46:20 »

Hi,

Anybody Please help,

I have loaded a terrain model into my scene and then got the shape3D.Geometry() for my model and loaded the geometry into a triangleArray.
I can now access vertices info etc.
Does anybody know how I can pinpoint a triangle on my model terrain - based on a single x,z (no y) coordinate

ie - looking down the y axis if I am at point x,z - on my terrain model - what triangle is that point in.

grateful for any ideas or help

Thanks

rmdire
Offline cascade

Junior Member




Java games rock!


« Reply #1 - Posted 2004-04-22 05:44:04 »

I am doing something like this for a simulation of a robotic vehicle driving on a heightfield based terrain.

You may use a rayIntersectsTriangle algorithm.

For my simulation I use a complete geometry outside Xith since I just started to work with Xith and have no idea about the collision stuff.

The following algorithm does the computation based on a plane defined by 3 points in 3d space. So its used like plane.rayIntersectsTriangle(beamStart,beamEnd, returnHitPoint);
Original is:
// From the rayIntersectsTriangle Algorithm of Tomas M?ller & Prosolvia Clarus AB

  // ========================================= public boolean rayIntersectsTriangle (minimally faster (5-10%) than v2 (does not create new intersection point)
   public boolean rayIntersectsTriangle3(point3d _s1, point3d _s2, point3d _rtn) {
     //System.out.println("RAY TRIANGLE INTERSECTION !");

     vector3d dir = new vector3d(_s2,_s1,false);

     vector3d edge1 = va;
     vector3d edge2 = vb;
     
     vector3d pvec = new vector3d(dir,edge2,false);
     
     double det = edge1.dotProduct(pvec);
     
     if ( det > -EPSILON && det < EPSILON ) {
         //System.out.println("IS PARALLEL !");
         return false;
     }
     
     double inv_det = 1.0 / det;
     
     vector3d tvec = new vector3d(_s1,a,false);
     
     double u = tvec.dotProduct(pvec) * inv_det;
     
     //System.out.println("u="+u);

     if (u < 0.0 || u > 1.0) {
         //System.out.println("NO INTERSECTION [1]!");
         return false;

     }

     vector3d qvec = new vector3d(tvec,edge1,false);
     
     double v = dir.dotProduct(qvec) * inv_det;
     //System.out.println("v="+v);
     if ( v < 0.0 || (u+v) > 1.0 ) {
         // System.out.println("NO INTERSECTION [2] !");
         return false;
     }
     
     double t = edge2.dotProduct(qvec)*inv_det;
     
     _s1.translate(dir,t,_rtn);
     
     //System.out.println("FOUND INTERSECTION ["+t+"] @ "+_rtn.x+" "+_rtn.y+" "+_rtn.z+" !");
     return true;
   }
Warning: the code may possibly incomplete due to cut and paste formatting problems.

This algorithm is based on my point,vector,plane classes which I coded without knowledge of javax.vecmath and I had no time yet to port them.

If thats what you are looking for contact me and I'll send (explay) the code.

evilscientist at gmx  net
Offline rmdire

Junior Member





« Reply #2 - Posted 2004-04-28 06:49:49 »

HI Cascade

I've tried to email you - but you don't seem to be getting the mail.

anyway - Yes please - any help and example code would be much appreciated.

Should this be of any interest to you - I have some code which Calculates the weight into a triangle from a specified point within the triangle area and uses that to calculate the y .

Cheers

rmdire
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

UprightPath (21 views)
2014-09-20 20:14:06

BurntPizza (27 views)
2014-09-19 03:14:18

Dwinin (40 views)
2014-09-12 09:08:26

Norakomi (70 views)
2014-09-10 13:57:51

TehJavaDev (95 views)
2014-09-10 06:39:09

Tekkerue (49 views)
2014-09-09 02:24:56

mitcheeb (70 views)
2014-09-08 06:06:29

BurntPizza (52 views)
2014-09-07 01:13:42

Longarmx (39 views)
2014-09-07 01:12:14

Longarmx (45 views)
2014-09-07 01:11:22
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

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

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

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

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

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!