#Need help in creating rubix cube
102 messages ยท Page 1 of 1 (latest)
โ This post has been reserved for your question.
Hey @gritty sandal! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
@vital halo Sorry bud for ping but can we talk ?
I guess
just join a VC
oh ok
So as you know i am creating 54 cubes
And while doing rotation i will move them
So when i apply rotation 2 thing will happen cubes will get rotated on its own axis also from center, as you can see in video
So main problem i am getting is rotation on cubes own center
And i need to solve that
All cube changing their location rightly i just need to do something about center rotation
I had one idea keeping track of all cubes location and its home location
(Here location means which side they belong either red,green,white etc)
And rotating it on its center according to this but i think its lengthy
You think there can be easy approch
yep it have same results
goes to right cordinates but center rotation messed up
I need to deal with center rotation
I thought resizing a cube when it enter to another side would be good but i think that will also not work
and the problem also occurs on the first rotation?
Which?
First rotation no problem
For any side
By adding cubes in a group class called cubeGroup
Can you show your cubeGroup?
And adding this class inside the scene
This one
I am just adding all cubes inside it
so you are transforming groups and not individual cubes?
And here it is added to scene
I am rotating individual cubes
but here, you add a transform to the whole group..?
Doing this so i can rotate the entire cube with mouse
its for this rotation
For rotation i am applying it to individual cubies
each of cube will rotate and transform
Can you try changing the rotation of a cube like that?
private Transform t=Rotate();
private box yourBox;
public void applyTransform(Transform toApply){
t = t.createConcatenation(toApply);
yourBox.getTransforms().clear();
yourBox.getTransforms().add(t);
}
(inspired from https://genuinecoder.com/javafx-3d-transform-objects-with-keyboard-input/)
rotation of cube or side
This one?
add that code to the cube
and when rotating it, first create the rotate object
and then call yourCube.applyTransform(yourRotate)
and do the same thing for all other transforms on individual cubes
not sure whether that makes a difference
Does the problem still occur if you don't do that rotation?
Obviously
You there
Did xou try the thing with concatenations?
I just made class with it and try to apply that to individual cube
public class x{
private Transform t=new Rotate();
public void applyTransform(Transform toApply, Cube c){
t = t.createConcatenation(toApply);
c.m_B.getTransforms().clear();
c.m_B.getTransforms().add(t);
}
}
public void rotateFront(Cube[][][] c, String direction,x X) {//YELLOW
float a = .55f;
for(int i=0; i<6; i++) {
for(int j=0; j<3; j++) {
for(int k=0; k<3; k++) {
if(c[i][j][k].m_B.getTranslateZ() <= -150 || c[i][j][k].m_B.getTranslateZ() <= -100) {
Rotate rotate = new Rotate();
rotate.setAxis(rotate.Z_AXIS);
if (direction.equals("clockwise")) {
rotate.setAngle(a);
//r.setAngle(0.5);
} else if (direction.equals("counterclockwise")) {
rotate.setAngle(-a);
//r.setAngle(-90);
}
X.applyTransform(rotate, c[i][j][k]);
rotate.setAngle(5);
// Move the cube to its new position
double angle = Math.toRadians(rotate.getAngle());
double newX = c[i][j][k].m_B.getTranslateX() * Math.cos(angle) - c[i][j][k].m_B.getTranslateY() * Math.sin(angle);
double newY = c[i][j][k].m_B.getTranslateX() * Math.sin(angle) + c[i][j][k].m_B.getTranslateY() * Math.cos(angle); c[i][j][k].m_B.setTranslateX(newX);
c[i][j][k].m_B.setTranslateX(newX);
c[i][j][k].m_B.setTranslateY(newY);
}
}
}
}
}
How to do this editor
No, I meant this as an instance method of your cube class
Oh ok
But still there is one problem budd
Where
double angle = Math.toRadians(rotate.getAngle());
double newX = c[i][j][k].m_B.getTranslateX() * Math.cos(angle) - c[i][j][k].m_B.getTranslateY() * Math.sin(angle);
double newY = c[i][j][k].m_B.getTranslateX() * Math.sin(angle) + c[i][j][k].m_B.getTranslateY() * Math.cos(angle); c[i][j][k].m_B.setTranslateX(newX);
c[i][j][k].m_B.setTranslateX(newX);
c[i][j][k].m_B.setTranslateY(newY);
THis?
at the end of that
My cubes will rotate on position
i need to move them in the forward to create rotation
oh I thought Rotate is doing both of these things
can you use a Translate object instead of doing the translation manually maybe?
But it will be same tbh
Nothing will be changed
Is it? Or would old rotations be applied to the new positions?
Nothing is working
-_-
or i am applying it wrong way
I am so frustrated man

what ate you doing?
You said apply that function rotation applied that
public void rotateFront(Cube[][][] c, String direction) {//YELLOW
float a = 90f;
for(int i=0; i<6; i++) {
for(int j=0; j<3; j++) {
for(int k=0; k<3; k++) {
if(c[i][j][k].m_B.getTranslateZ() <= -150 || c[i][j][k].m_B.getTranslateZ() <= -100) {
Rotate rotate = new Rotate();
rotate.setAxis(rotate.Z_AXIS);
if (direction.equals("clockwise")) {
rotate.setAngle(a);
//r.setAngle(0.5);
} else if (direction.equals("counterclockwise")) {
rotate.setAngle(-a);
//r.setAngle(-90);
}
c[i][j][k].applyTransform(rotate);
// Move the cube to its new position
double angle = Math.toRadians(rotate.getAngle());
double newX = c[i][j][k].m_B.getTranslateX() * Math.cos(angle) - c[i][j][k].m_B.getTranslateY() * Math.sin(angle);
double newY = c[i][j][k].m_B.getTranslateX() * Math.sin(angle) + c[i][j][k].m_B.getTranslateY() * Math.cos(angle); c[i][j][k].m_B.setTranslateX(newX);
c[i][j][k].m_B.setTranslateX(newX);
c[i][j][k].m_B.setTranslateY(newY);
}
}
}
}
}
Btw how to send code in that window
I thibk manually applying the translations with setTranslateX instead of using a Translate object could be the cause of the issue
but I am not experienced with JavaFX 3D stuff
or any 3D stuff
Atlest you helpin man thats great thing , I am great someone is helping me :]
All other server are dead
-_-
not really
Me closing this post
I will apply that approch keeping track of all side and add rotation according to it
Have a great day
And take care because i need more help in future ๐
btw you don't need to lose the post before you solve your problem
Oh i thought it will automatically close
So i close whenever i go offline