Author Topic: Surface Normal  (Read 2708 times)

Offline AO

  • byte
  • *
  • Posts: 5
    • View Profile
Surface Normal
« on: May 14, 2013, 08:20:21 pm »
Hey there. I gotta do some ball bouncing over a cube, which is obviously an even surface. When I detect the collision I'm trying to get the corresponding surface normal. Since it is a cube, which is no rotated nor moved or anything, I expect to get a normal with only one axis component (i.e.:[0.0, -1.0, 0.0]), but I get different values for different collision events, even though the ball is bouncing all the time over the same side on the mentioned cube. The normals I get are close to the one I expect, but are not exactly the ones I'm expecting, thus creating some funny behaviour on some bounces (as if the surfave was kind of rugged). Please if someone can help me out, I'd appreciate it. Cheers!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Surface Normal
« Reply #1 on: May 14, 2013, 08:27:59 pm »
How do you get these normals and how much do they differ (some example values might help)?

Offline AO

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Surface Normal
« Reply #2 on: May 15, 2013, 06:53:44 pm »
All I have is a sphere and a cube (or a plane), both from Primitives. When a collision occurs, I get the polygon normal from "CollisionEvent". An example of the values is (0.0032, -0.9936, 0.0032)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Surface Normal
« Reply #3 on: May 15, 2013, 09:36:40 pm »
...and that's the reason for my question: There is no method to get the surface normal in CollisionEvent. I'm confused... ???

Offline AO

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Surface Normal
« Reply #4 on: May 15, 2013, 09:52:11 pm »
Yes, you're right, you can't do retrieve it directly, so I get the polygons id's
Code: [Select]
CollisionEvent.getPolygonIds()
and given that I get the normal out of
Code: [Select]
PolygonManager.getTransformedNormal(int polyID)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Surface Normal
« Reply #5 on: May 16, 2013, 08:35:19 am »
I had a look at that method...the differences in the values that you experience are simply caused by numerical inaccuracies that add up in the process. That's normal behaviour and usually not a problem, because the differences are so tiny that they are neglectable in most cases.
However, looking at the method, it seems to be rather inefficient anyway. I've uploaded a new beta version here: http://jpct.de/download/beta/jpct_ae.jar that implements this in a more efficient way with the additional effect, that numerical accuracy should have been improved. Please give it a try.

Offline AO

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Surface Normal
« Reply #6 on: May 16, 2013, 03:46:31 pm »
All right, thanks a lot. I'll give it a try and get back to you feedback. Keep up the good work!

Offline AO

  • byte
  • *
  • Posts: 5
    • View Profile
Re: Surface Normal
« Reply #7 on: May 18, 2013, 01:56:03 am »
Problem solved mate, thanks.