1 (edited by Slenkar 2009-03-09 12:08:06)

Topic: how to rotate camera

heres the code:

SuperStrict
Framework Irrlicht.Core



Local receiver:IEventReceiver=IEventReceiver.Create(MyEventReceiver.generate)

Local device:IrrlichtDevice = ..
    IrrlichtDevice.Create(EDT_DIRECT3D9, _DIMENSION2DI(640, 480), 16, ..
        False, False, False, receiver)
        Local driver:IVideoDriver = device.getVideoDriver()
Local smgr:ISceneManager = device.getSceneManager()
Local guienv:IGUIEnvironment = device.getGUIEnvironment()
Rem
We add a hello world label To the window, using the GUI environment.
EndRem
guienv.addStaticText("Hello World! This is the Irrlicht Software renderer!", ..
    _RECTI(10,10,260,22),True)
device.setWindowCaption("Hello World! - Irrlicht Engine Demo")

Local mesh:IMesh = smgr.getMesh("ship_models/11.b3d")


Global node:ImeshSceneNode = smgr.addmeshSceneNode(mesh)

Global globnode:Ilightscenenode=smgr.addlightscenenode()
Function TFormPoint:Vector3df(x:Float,y:Float,z:Float,source:ISceneNode,dest:ISceneNode)
    Local lastTForm:Vector3df=_VECTOR3DF(x,y,z)

    ' first convert to world from the source
    If source Then source.getAbsoluteTransformation().transformVect(lastTForm)

    ' now from world to local
    If dest Then dest.getRelativeTransformation().transformVect(lastTForm)
    
    Return lastTForm
EndFunction

If (node)
    node.setMaterialFlag(EMF_LIGHTING, False)
    'node.setMD2Animation ( EMAT_STAND )
    node.setMaterialTexture( 0, driver.getTexture("ship_models\blueship-low.png") )
EndIf

Type MyEventReceiver Extends IEventReceiver
    Method OnEvent:Int(event:SEvent)
    
        If (node And event.getEventType()=EET_KEY_INPUT_EVENT And ..
            Not event.getKeyPressedDown())
            
            Local key:Int=event.getKeyInputKey()
                    
            Select key
                Case EKEY_KEY_W
                    Local v:Vector3df=node.GetRotation()
                    v.setY(v.getY()+2.0)
                    node.SetRotation(v)
                    Return True
                Case EKEY_KEY_S
                    Local v:Vector3df=node.GetRotation()
                    v.setY(v.getY()-2.0)
                    node.SetRotation(v)
                    Return True
                Default
                    Return False
            EndSelect
        EndIf

        Return False
    EndMethod

    ' we must override the generate function in order for instantiation to work properly
    Function generate:IEventReceiver()
        Return New MyEventReceiver
    EndFunction
EndType

Global camera:Icamerascenenode=smgr.addCameraSceneNode()'(Null, _VECTOR3DF(0,30,-40), _VECTOR3DF(0,5,0))


Local i#
node.SetRotation(_vector3df(0,90,0))
While(device.run())

    driver.beginScene(True, True, _SCOLOR(0,0,0,140))


node.setposition(TFormPoint(0,0,10,node,globnode))
Local nodepos:vector3df=node.getposition()
Local noderot:vector3df=node.GetRotation()

camera.setposition(TFormPoint(0,0,15,node,globnode))
camera.SetRotation(noderot)

    smgr.drawAll()
    guienv.drawAll()

    driver.endScene()
Wend


device.drop()

thing is, no matter what I change the camera rotation to.. it always points at the mesh, instead of pointing in the same direction as the mesh.

AND

if i put the camera behind the mesh it NEVER faces the ship

EDIT
nevermind I had to bind the cameras rotation and target

Re: how to rotate camera

That's because cameras are always pointing at a target. You would have to change to camera target too.
Check out irrb3d for this there should be the solution somewhere.

3 (edited by Slenkar 2009-03-10 06:46:44)

Re: how to rotate camera

got it, thanks

It was pointing at 0.0.0 smile

Re: how to rotate camera

greetings smile  there is a new method in v1.5 on ICameraSceneNode that makes the camera look in the same direction as rotations.  look up the method:

ICameraSceneNode.bindTargetAndRotation()

Re: how to rotate camera

got it thanks