# www.jpct.net

## jPCT - a 3d engine for Java => Support => Topic started by: PaldxD on February 23, 2011, 11:46:13 pm

Title: Small Question
Post by: PaldxD on February 23, 2011, 11:46:13 pm
Complex to say.
So I will graphically demonstrate the problem.
(http://img341.imageshack.us/img341/8901/problemtx.jpg)

Why after I add as a child he "translates" there? and this is not where?
Title: Re: Small Question
Post by: EgonOlsen on February 23, 2011, 11:57:36 pm
I don't get the problem... ???
Title: Re: Small Question
Post by: PaldxD on February 24, 2011, 12:23:11 am
http://img341.imageshack.us/i/problemtx.jpg/

I need to make when adding a child in another cube it does not translate to another corner.
how to explain ...
as in the photo, while adding another child of the cube as cube it rotates back ...

too complex to explain, but it is something simple
Title: Re: Small Question
Post by: Kaiidyn on February 24, 2011, 01:04:14 am
Could you post some code ? Might help to show the problem better..
Title: Re: Small Question
Post by: EgonOlsen on February 24, 2011, 12:18:22 pm
Yes, some code might help, because i still understand the problem. Which cube in that picture is right or wrong or expected to be different? Which one is the child of which?
Title: Re: Small Question
Post by: PaldxD on February 24, 2011, 03:27:24 pm
Let's go!

Code: [Select]
` for (int i = 0 ; i<25;i++){ ball.rotateZ((float) ((2.0f / 25) * Math.PI)); cub = Primitives.getCube(1); ball.addChild(cub); }`
"forming a flower"
Title: Re: Small Question
Post by: Nick on February 24, 2011, 06:08:33 pm
It's still not clear what you want, but I can make some guesses what's going wrong.

You can probably use some of these functions for some objects when rotating and translating:
setRotationMatrix(new Matrix());
setTranslationMatrix(new Matrix());

Also did you mention that you didn't use the i variable in the for loop?

If you're still stuck, please post some more code or explain what you want to achieve.
Title: Re: Small Question
Post by: EgonOlsen on February 24, 2011, 09:50:49 pm
Seems as if you somehow expect cub to get the current rotation from "ball" assigned at the moment where you add it as child, but that's not the case. Your code rotates ball 25 times and makes each cub a child of ball, so that each cub inherits the same rotation of 25*(2.0f/25). I'm not sure if the child/parent relations is really what you are after in this case.
Title: Re: Small Question
Post by: PaldxD on February 24, 2011, 10:34:21 pm
This is fail!!!

but....

http://www.4shared.com/file/NW-FYi2e/try.html

check this. :(
Title: Re: Small Question
Post by: EgonOlsen on February 24, 2011, 11:48:19 pm
When you add cube2 as a child of ball, it will do the same rotation as the ball. It's only natural that it changes its position according to the balls rotation. I'm still not really sure what exactly you want. The second slide looks like the first one to me except that the cube carries another number. Anyway, try something like

Code: [Select]
`for (int i = 0 ; i<25;i++){ ball.rotateZ((float) ((2.0f / 25) * Math.PI));        cub = Primitives.getCube(1); cub.setRotationMatrix(ball.getRotationMatrix().cloneMatrix());        cub.translate(?,?,?); // Position on top of ball, the same for each cub        cub.setRotationPivot(<position of ball's transformed center-cub's transformed center>);}`
That's untested...it might not work but maybe it's a starting point. I don't think that a child relation between cub and ball is what you want here.
Title: Re: Small Question
Post by: PaldxD on February 25, 2011, 12:13:25 am
solution!

Code: [Select]
` for (float i = 0; i < 25; i++) { ball.rotateZ((float) ((2.0f / 25) * Math.PI)); cube = Primitives.getCube(1); cube.translate((float) (10 * Math.sin(i * (2f / 25f) * Math.PI)), (float) (10 * Math.cos(i * (2f / 25f) * Math.PI)), 0); cube.setRotationMatrix(ball.getRotationMatrix().cloneMatrix()); ball.addChild(cube); world.addObject(cube); }`