Login  Register

Re: Rubik's Cube Help!

Posted by sachuraju on Apr 24, 2013; 3:58am
URL: https://forum.world.st/Rubik-s-Cube-Help-tp4682659p4683220.html

Ok..

I'm now trying to arrive at the transformation matrix that will give me the required rotation, and this is what I've come up with. It isn't working as I expect it to.


rotateBy: anAngle aroundX: xValue y: yValue z: zValue              
"xyz is the point around which I want to rotate the object. I'll call it the origin"

    prevTrans := localTransform translation.
    "store the current position of the object"

    diffTrans := (Vector3 x: xValue y:yValue z:zValue) - prevTrans.  
    "Get the difference between origin and current position"

    transformMatrix  := Matrix4x4 identity.
    "To build the transformation matrix, start with the identity"

    transformMatrix  addTranslation: diffTrans.
    "add transformation to translate the object to the origin"

    transformMatrix  := transformMatrix rotation: anAngle aroundX:xValue y:yValue z:zValue.
    "add transformation to rotate the object by some angle at the origin"

    transformMatrix addTranslation: (diffTrans negated).
    "add transformation to translate the object to its new position"
       
    localTransform := transformMatrix * localTransform.
    "using the generate transformation matrix to apply the transformation to the object's localTransform".

With this, I was really expecting to get the desired result but am not getting it. What am I missing here?