Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (788)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (860)
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 37399 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.

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);

      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;


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


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=";hl=en_US&amp;start=" target="_blank">;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: 661

« 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 »


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:

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  

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

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

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

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

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

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

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

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

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

nelsongames (3752 views)
2018-04-24 18:14:32
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

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20 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‑
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!