Home Tutorials Download Beta Store Forum Documentation KnowledgeBase Wiki Blog

ShiVa3D

Return to Microsoft Windows

Rotation localTransform problem  [SOLVED]

Windows DX9/OpenGL 2 Standalone Apps

Re: Rotation localTransform problem

Postby rasq » 30 Dec 2010, 01:45

broozar wrote:why do you change from global to local space in the first place, what is your goal.

your rotation issue is easily explained. curAngleX will cause problems in local space - my understanding is this: in local space, the rotation is reset after each frame. so after one bit of rotation per frame, your object will have a rotation of 0,0,0 in local space. curAngleX is computed by math.interpolate ( this.nCurAngleX ( ), this.nDstAngleX ( ), 10 * dt ) while nDstAngleX is compused of this.nDstAngleX ( this.nDstAngleX ( ) - nDeltaX * 90 ) , nDeltaX being the value your onMouseMove handler sends object.sendEvent ( application.getCurrentUserActiveCamera ( ), "OSVCamera", "onRotateBy", nDeltaX, nDeltaY ). in other words, this.nDstAngleX ( ) - nDeltaX * 90 assumes a global inertial system and will deliver an abolute angle value, a value that can never be reached in a local system because the coordinate system will get reset after every frame.


then, what i can do to correct compute this angle???
rasq
Junior Boarder
Junior Boarder
 
Posts: 37

Re: Rotation localTransform problem

Postby broozar » 30 Dec 2010, 10:28

leave it in global space, where it belongs.
User avatar
broozar
Platinum Boarder
Platinum Boarder
 
Posts: 3349
Location: Berlin - Germany

Re: Rotation localTransform problem

Postby rasq » 30 Dec 2010, 12:14

Then, what I can do to achive my goal??
rasq
Junior Boarder
Junior Boarder
 
Posts: 37

Re: Rotation localTransform problem

Postby broozar » 30 Dec 2010, 12:21

User avatar
broozar
Platinum Boarder
Platinum Boarder
 
Posts: 3349
Location: Berlin - Germany

Re: Rotation localTransform problem

Postby rasq » 30 Dec 2010, 12:58

Somthing like this:

Code: Select all
local obiekt = this.getObject ( )
   
    local Ex, Ey, Ez = object.getTranslation ( this.getObject ( ), object.kGlobalSpace )   
    object.lookAt ( obiekt, Ex, Ey, Ez , object.kGlobalSpace, 0.2 )
     
     
    local hCam = application.getCurrentUserActiveCamera ( )
    if ( hCam )
    then   
        object.rotateAround ( obiekt, 0, -2, 2, 0, application.getLastFrameTime ( )*20, 0, object.kLocalSpace )
    end




?
rasq
Junior Boarder
Junior Boarder
 
Posts: 37

Re: Rotation localTransform problem

Postby broozar » 30 Dec 2010, 13:12

i thought you wanted your cam to look at 0,0,0 all the time, not the position it (this. is your cam?) is currently at.
your camera rotation does not take the mouse into consideration, plus you are trying to rotate in local space again around a fixed point... do you understand your own code? looks c&p from the docs to me with some changes that rather break the stuff.

really, have a look at the fps example, how they rotate the cam there. it will be much easier for you than stabbing in the dark.

and no, i will not write code for you. you will figure it out, it is not too complicated.
User avatar
broozar
Platinum Boarder
Platinum Boarder
 
Posts: 3349
Location: Berlin - Germany

Re: Rotation localTransform problem  [SOLVED]

Postby rasq » 30 Dec 2010, 16:58

Thx, for Your help.

My error was, camera rotate all time.

This work fine for me (and some minor changes on place where anle is compute):


Code: Select all
    local hScene = application.getCurrentUserScene ( )   
    local hObject = scene.getTaggedObject ( hScene, "myObject" )

   

    if ( hObject ~= nil )
    then
            object.setRotation      ( hObject, 0, curAngleX, 0, object.kGlobalSpace )
            object.rotate           ( hObject, curAngleY, 0, 0, object.kLocalSpace )
    end
rasq
Junior Boarder
Junior Boarder
 
Posts: 37

Previous

Return to Microsoft Windows

cron