www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Nemetz on August 03, 2011, 10:41:01 am

Title: Strange values in object polygons normals.
Post by: Nemetz 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)
Title: Re: Strange values in object polygons normals.
Post by: EgonOlsen 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.
Title: Re: Strange values in object polygons normals.
Post by: Nemetz 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....
Title: Re: Strange values in object polygons normals.
Post by: EgonOlsen 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.
Title: Re: Strange values in object polygons normals.
Post by: Nemetz 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?
Title: Re: Strange values in object polygons normals.
Post by: EgonOlsen on August 04, 2011, 10:17:21 am
Well..yes...i don't get it... ???
Title: Re: Strange values in object polygons normals.
Post by: Nemetz on August 04, 2011, 10:30:30 am
What exactly, my task?) Or my  decision? :)
Title: Re: Strange values in object polygons normals.
Post by: EgonOlsen on August 04, 2011, 10:46:20 am
Your actual problem...
Title: Re: Strange values in object polygons normals.
Post by: Nemetz 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?
Title: Re: Strange values in object polygons normals.
Post by: EgonOlsen on August 04, 2011, 11:53:43 am
Try to rotate it around the axes returned by get?Axis() instead.
Title: Re: Strange values in object polygons normals.
Post by: Nemetz 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(
Title: Re: Strange values in object polygons normals.
Post by: EgonOlsen 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.
Title: Re: Strange values in object polygons normals.
Post by: Nemetz on August 04, 2011, 02:36:49 pm
Ok, thank you!
i will try!