Author Topic: Small Question  (Read 2302 times)

Offline PaldxD

  • byte
  • *
  • Posts: 25
    • View Profile
Small Question
« on: February 23, 2011, 11:46:13 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Small Question
« Reply #1 on: February 23, 2011, 11:57:36 pm »
I don't get the problem... ???

Offline PaldxD

  • byte
  • *
  • Posts: 25
    • View Profile
Re: Small Question
« Reply #2 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

Offline Kaiidyn

  • long
  • ***
  • Posts: 103
    • View Profile
Re: Small Question
« Reply #3 on: February 24, 2011, 01:04:14 am »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Small Question
« Reply #4 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?

Offline PaldxD

  • byte
  • *
  • Posts: 25
    • View Profile
Re: Small Question
« Reply #5 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"

Offline Nick

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Small Question
« Reply #6 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Small Question
« Reply #7 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.

Offline PaldxD

  • byte
  • *
  • Posts: 25
    • View Profile
Re: Small Question
« Reply #8 on: February 24, 2011, 10:34:21 pm »
This is fail!!!

but....



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

check this. :(

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Small Question
« Reply #9 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.

Offline PaldxD

  • byte
  • *
  • Posts: 25
    • View Profile
Re: Small Question
« Reply #10 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);
}