Sorry, I’ve tried to wrap my head around vector operations in the documentation, but can’t seem to get there.
I’m trying to modify the Hello Picking tutorial so that the red sphere that marks the contact point is flush on the marked surface, rather than embedded. The marking sphere is initialized like so:
Sphere sphere = new Sphere(30, 30, 0.2f);
For each detected intersection between a Ray and a Shootable, a vector is returned:
Vector3f pt = results.getCollision(i).getContactPoint();
And the closest contact point is used to make the mark.
So if I wanted the sphere to be translated from the contact point, minus its radius toward the user, how would I accomplish this?
To do so, you also need the normal at the contactPoint.
CollisionResult gives it to you. I just forgot its name…
Then you just compute
[java]newPt = pt.add(normal.mult(radius));[/java]
@yang71 actually that would move it out from the face - to move it directly back towards the camera he wants to actually move it along (cam.location-contact.location)*radius.
Hm, yang71’s suggested approach actually does seem to give the desired effect (thanks!). I don’t understand the concepts well enough to know why it does, and why zarch’s correction isn’t actually correct.
Well. In fact, @Zarch correction is correct. Sorry for my wrong “good” proposal…
The normal is orthogonal to the surface at the contact point. Thus the sphere touches the surface at the contact point, but do NOT go toward the user.
The proposal of @Zarch is to use (USER - CONTACT) to update the contact point. What misses in this is just a normalize() that just divides by the distance to the user. This is the right answer to your original question (toward the user). But maybe not what you really wanted
Yeah, the difference between the approaches is subtle-both move your ball away from the contact point, the question is where you move it directly away from the surface contacted or whether you move it back towards the camera.
If you look directly in at the surface there will be no difference, as the camera angle moves though the difference will appear.