Small Question

Started by PaldxD, February 23, 2011, 11:46:13 PM

Previous topic - Next topic

PaldxD

Complex to say.
So I will graphically demonstrate the problem.


Why after I add as a child he "translates" there? and this is not where?

EgonOlsen

I don't get the problem... ???

PaldxD

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

Kaiidyn

Could you post some code ? Might help to show the problem better..
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer's intent but rather is full of crisp abstractions and straightforward lines of control. - Grady Booch

EgonOlsen

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?

PaldxD

Let's go!

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"

Nick

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.

EgonOlsen

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.


EgonOlsen

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


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.

PaldxD

solution!   

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);
}