Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (754)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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  
  Collision with ray picking problem.  (Read 21754 times)
0 Members and 1 Guest are viewing this topic.
Offline Akinesis

Senior Newbie


Exp: 3 years



« Posted 2014-09-25 10:57:45 »

Hello, i've implemented a ray picking function in my game (the function is not my and work like it should by returning a normalized direction vector) but i cant make it work correctly with the collision.

My probleme is that every things is fine as long as the X direction is positive and the Z position negativ. Otherwise i go strange output and the think just not working.

I've manage to see that when X i negativ the difference between what my code gave and what it should be is
"function output x" + xDirection*10 but just correcting this difference with a small if gave even weirder results.

If anyone can look at my code and tell me if he see something, it would be great. I'll share the function (every input use are accurate and the problem don't come from there, i've test them each one at a time). I'll also share you a quick example of test (input-> output) and if you want to see it, an "in game" video of the result.

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  
private void setRayCoord(){

      float xStart = -(float)posCam.getX();
      float yStart = -(float)posCam.getY();
      float zStart = -(float)posCam.getZ();
     
      double rayX = ray.x;
      double rayZ = ray.z;

      boolean xNeg = ray.x<0;
      boolean zPos = ray.z>0;

      Vector3f origine = new Vector3f(xStart, yStart, zStart);

      System.out.println("avant : "+ray);
      System.out.println("Caméra : "+xStart +", "+zStart);
      System.out.println("=====");

      ray.x *= 5;
      ray.z *= 5;

      ray.x += origine.x;
      ray.z += origine.z;
     
      //ray.x += (xNeg)?rayX*10:0;
      //ray.z -= (zPos)?rayZ*10:0;


      System.out.println(ray);
      System.out.println("---------------------------------");

      picker.setPos(ray.x, yStart, ray.z);

   }


Tests:
1  
2  
3  
4  
5  
Ray.x : 0.89   camera.x : 9.33  outPut.x : 13.79
Ray.z : -0.29  camera.z : 8.55  outPut.z : 7.08

Ray.x : -0.89   camera.x : 9.33  outPut.x : 4.86
Ray.z : +0.29  camera.z : 8.55  outPut.z : 10.03


The video:
<a href="http://www.youtube.com/v/wy4wHkxR6ZQ?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/wy4wHkxR6ZQ?version=3&amp;hl=en_US&amp;start=</a>

What doesn't kill you, give you XP.
Offline Akinesis

Senior Newbie


Exp: 3 years



« Reply #1 - Posted 2014-11-29 13:03:58 »

Up on this topic pleas. I'm still stuck with this problem, i can"t figure it down.

What doesn't kill you, give you XP.
Offline KaiHH

JGO Kernel


Medals: 520



« Reply #2 - Posted 2014-11-29 14:16:18 »

I am sure people would really like to help you out on this, but from your post it is not clear what your problem actually is.

You need to be more specific about your problem and explain in more detail the following points:

- what do you mean with: you cannot "make [ray picking] work correctly with the collision." What collision? Who collides with whom?
- it is not obvious what you want to achieve with negating your camera's position (mirroring it about the origin of the coordinate system), if that is what "posCam" contains
- it is also not obvious, what "ray" contains and why one wants to check for it being negative at all.
- also, why are you scaling "ray" (and only x and z) by 5?
- and last but not least, why do you offset your "ray" which ought to be a direction (I guess) by your camera's position, which ought to be a position?

Also, from your video it is not obvious what the wireframe box should be and what you expect to happen.
Currently, I do not see anything wrong with your camera rotating about some point near that box. :-)
Looks nice, by the way!

Cheers, Kai
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #3 - Posted 2014-11-29 21:04:15 »

Hi

Up on this topic pleas. I'm still stuck with this problem, i can"t figure it down.
The emergency is for you, not for us. We do our best but we owe you nothing except respect.

I use "ray picking" in ArdorCraft, you can look at how it is implemented to see what is wrong in your own code:
https://github.com/gouessej/Ardor3D/blob/master/ardor3d-core/src/main/java/com/ardor3d/bounding/BoundingBox.java#L666

Julien Gouesse | Personal blog | Website | Jogamp
Offline basil_

« JGO Bitwise Duke »


Medals: 418
Exp: 13 years



« Reply #4 - Posted 2014-11-29 21:19:23 »

i'm pretty sure we could help you if we'd understand what you're trying to do. Smiley

- projecting screen coords to a ray in 3D ?
- ray-AABB intersect ?
- ray-triangle intersect ?
Offline Akinesis

Senior Newbie


Exp: 3 years



« Reply #5 - Posted 2014-11-30 13:55:49 »

Hello, tanks for responding so quick. First i apologized if i offend you in some way, english is not my native language and i may have exprime myself wrong. I'm really thankful for the help any of you can provide to me.

To clarify my problem, i'm trying to implement ray picking to my (of course) 3D project. For what i understund to ray picking (so that what i'm trying to do) is to compute a ray (a vector) starting to the camera and heading to the distant point le camera/player is looking.

So i first need to calculate the direction of where the camera is looking (which is made with a function i took on a active membre of this forum and wich return a normalized vector x,y,z of the direction).
Then i take the position of the camera in my 3D space, this is pretty easy of course. And according to the mathematical function i find online, i try to find a second point on that ray further away. The function i find is ray*distance+origine.

This is the part that is not working. When i use the terme "collision" i meant colliding in the 3D space at the distance i want (5 blocks / units in the code i shared). The result i have are pretty awkward and i realy not sure why it's doing that. The short video i share show how it's almost working.

Once again sory for my bad english i doing my best, and thanks again for all the help you could provided. I don't want to be rude, i'm just stuck whit this for while and i'm a little desperate :p.

Edit: in my video we can the the wired cube moving with my cursor but it should always been center with it. Also i currently not working on the Y axis because it les problem and once it will work on the other axis it will be easy to apply it on Y.

I want to finish with this : i have almost no idea of what i'm doing, my brain usually stop working properly want it comes to math.

What doesn't kill you, give you XP.
Offline Akinesis

Senior Newbie


Exp: 3 years



« Reply #6 - Posted 2014-12-02 19:56:20 »

Also, for what i've tried so far, it's seems to be math(or trigonometry which is almost the same)-only problem. But i'm not sure, i'm not very skilled in openGL ether.

What doesn't kill you, give you XP.
Pages: [1]
  ignore  |  Print  
 
 

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

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

nelsongames (70 views)
2018-04-24 18:14:32

ivj94 (752 views)
2018-03-24 14:47:39

ivj94 (82 views)
2018-03-24 14:46:31

ivj94 (622 views)
2018-03-24 14:43:53

Solater (98 views)
2018-03-17 05:04:08

nelsongames (179 views)
2018-03-05 17:56:34

Gornova (405 views)
2018-03-02 22:15:33

buddyBro (1065 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!