Author Topic: Strange values in object polygons normals.  (Read 5894 times)

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Strange values in object polygons normals.
« on: August 03, 2011, 10:41:01 am »
Hi!
In your demo example, i'm trying to rotate object adround Y Axis like this:
Code: [Select]
public static final float NINETY_DEGREES = 1.570796327f;
        .....

if (touchTurn != 0) {
cube.rotateY(NINETY_DEGREES);
touchTurn = 0;
}

and trying to get nomall vector of polygon, which i'm picking:
Code: [Select]

@Override
public void collision(CollisionEvent ce) {

ce.getTargets();
int[] ids = ce.getPolygonIDs();;
for (int i = 0; i < ids.length; i++){
Logger.log("poligon id is" + ids[i]);
}
Logger.log("name of picked object are " + this.getName());
TextureBox box = (TextureBox)ce.getObject();
if (box != null){
Logger.log("Normalized X Axis" + box.getXAxis().normalize().toString());
Logger.log("Normalized Y Axis" + box.getYAxis().normalize().toString());
Logger.log("Normalized Z Axis" + box.getZAxis().normalize().toString());

Logger.log("getTransformedNormals" + box.getPolygonManager().getTransformedNormal(ids[0]).toString());


}


}

so, i have only 4 direction when i'm rotating my cube. But i reciving a lot of different values when i try getAxis, and getTranformedNormall.  Only at the first time i'm getting correct values. And i'm confused in this when i'm facing this problem.
Example:
Code: [Select]
1:
I/jPCT-AE ( 6221): Normalized X Axis(1.0,0.0,0.0)
I/jPCT-AE ( 6221): Normalized Y Axis(0.0,1.0,0.0)
I/jPCT-AE ( 6221): Normalized Z Axis(0.0,0.0,1.0)
I/jPCT-AE ( 6221): getTransformedNormals(-0.0,-0.0,-1.0)

2:
I/jPCT-AE ( 6221): Normalized X Axis(8.3051646E-7,0.0,1.0)
I/jPCT-AE ( 6221): Normalized Y Axis(0.0,1.0,-0.0)
I/jPCT-AE ( 6221): Normalized Z Axis(-1.0,0.0,8.3051646E-7)
I/jPCT-AE ( 6221): getTransformedNormals(-8.2651775E-7,-0.0,-1.0)

3:
I/jPCT-AE ( 6221): Normalized X Axis(-4.371139E-8,0.0,-1.0)
I/jPCT-AE ( 6221): Normalized Y Axis(0.0,1.0,-0.0)
I/jPCT-AE ( 6221): Normalized Z Axis(1.0,0.0,-4.371139E-8)
I/jPCT-AE ( 6221): getTransformedNormals(-6.357829E-8,-0.0,-1.0)
4:
I/jPCT-AE ( 6221): Normalized X Axis(-1.4424753E-6,0.0,-1.0)
I/jPCT-AE ( 6221): Normalized Y Axis(0.0,1.0,0.0)
I/jPCT-AE ( 6221): Normalized Z Axis(1.0,0.0,-1.4424753E-6)
I/jPCT-AE ( 6221): getTransformedNormals(-1.4623007E-6,-0.0,-1.0)
5:
I/jPCT-AE ( 6221): Normalized X Axis(-1.0,0.0,1.1364959E-6)
I/jPCT-AE ( 6221): Normalized Y Axis(-0.0,1.0,0.0)
I/jPCT-AE ( 6221): Normalized Z Axis(-1.1364959E-6,0.0,-1.0)
I/jPCT-AE ( 6221): getTransformedNormals(-1.1444092E-6,0.0,-1.0)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Strange values in object polygons normals.
« Reply #1 on: August 03, 2011, 11:17:45 am »
I don't the actual problem here...are you talking about these 1.1364959E-6-like things? If so, then these are inaccuracies that happen when dealing with floats and nothing to worry about.

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Re: Strange values in object polygons normals.
« Reply #2 on: August 03, 2011, 11:48:16 am »
Well, actually i confused about this values:
8.3051646E-7 or -4.371139E-8 or -6.357829E-8....

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Strange values in object polygons normals.
« Reply #3 on: August 03, 2011, 12:11:23 pm »
As said, these are inaccuracies due to the limitations of the floating point format. They are so close to 0 that it doesn't matter. Don't worry about them.

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Re: Strange values in object polygons normals.
« Reply #4 on: August 04, 2011, 08:48:08 am »
Hm, but with the normals vectors i,m tring to determine object position and orientation in world...
For it's rotation after picking, etc.
So , i thought use for this task unit vector, i mean polygon normals.
Maybe this task has another decision?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Strange values in object polygons normals.
« Reply #5 on: August 04, 2011, 10:17:21 am »
Well..yes...i don't get it... ???

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Re: Strange values in object polygons normals.
« Reply #6 on: August 04, 2011, 10:30:30 am »
What exactly, my task?) Or my  decision? :)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Strange values in object polygons normals.
« Reply #7 on: August 04, 2011, 10:46:20 am »
Your actual problem...

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Re: Strange values in object polygons normals.
« Reply #8 on: August 04, 2011, 10:52:57 am »
Ok, i'll try to explain...
i have some object, and after picking it, i want to rotate it. Rotation can be in 4 directions - left, right, up, down.
For example:
i rotete object twice: to the left and to the right, rotation was around Y axis.
Then i rotate object up, and  aafter i want to rotate it to the left. If i'll rotate it around y axis , that wil be wrong rotation, You agree?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Strange values in object polygons normals.
« Reply #9 on: August 04, 2011, 11:53:43 am »
Try to rotate it around the axes returned by get?Axis() instead.

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Re: Strange values in object polygons normals.
« Reply #10 on: August 04, 2011, 01:06:41 pm »
Yes, i know, and i'm doing it right now. But i don't now the orentation of the object in  the world.
So, at the moment i dont' know about which axish i must rotate object.
And for detection of orientation in the world i'm trying to use normalls, but they are returns some magic not normalls results(

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Strange values in object polygons normals.
« Reply #11 on: August 04, 2011, 02:30:58 pm »
It's bad practice to compare floating point numbers to a fixed value anyway. Us a range (-0.01-0.01 and 0.99-1.01 for example) and it should work fine.

Offline Nemetz

  • int
  • **
  • Posts: 53
    • View Profile
Re: Strange values in object polygons normals.
« Reply #12 on: August 04, 2011, 02:36:49 pm »
Ok, thank you!
i will try!