#0 

07-06-2008 14:34:49

acropole
Petit nouveau
Date d'inscription: 07-06-2008
Messages: 1

Bonjour,

Je suis en train d'essayer d'implémenter un nouveau type de camera (sans gimbal lock) qui n'existe pas dans irrlicht.
J'ai donc créé ma caméra dérivée de ICameraSceneNode.
Ca compile, sans tourne sans bug, mais ça n'affiche rien sad

a priori ça vient de ma camera, car avec une camera d'irrlicht ça marche.
J'imagine que j'ai du oublier de définir correctement un paramètre ou d'appeler un fonction de rendu.

Voici ma classe

Fichier .h

Code:

#ifndef _AMHCAMERASCENENODE_
#define _AMHCAMERASCENENODE_
#include <irrlicht.h>

#include "amhEventReceiver.h"

using namespace irr;
using namespace core;
using namespace scene;

enum movements{
    MOVE_FORWARD = 0,
    MOVE_BACKWARD,
    MOVE_LEFT,
    MOVE_RIGHT,
    MOVE_UP,
    MOVE_DOWN
};

class amhCameraSceneNode :
    public ICameraSceneNode
{
public:
    void setProjectionMatrix(const core::matrix4& projection);
    void setUpVector(const core::vector3df& pos);
    void setTarget(const core::vector3df& pos);
    void setNearValue(f32 zn);
    void setFarValue(f32 zf);
    void setAspectRatio(f32 aspect);
    void setFOV(f32 fovy);
    void setInputReceiverEnabled(bool enabled);
    void setEventReceiver(amhEventReceiver* ereceiver);
    bool isInputReceiverEnabled() const;
    void setCursorControl(ICursorControl* icc);
    void setDevice(IrrlichtDevice* d);

    const core::aabbox3d<f32>& getBoundingBox() const;

    const core::matrix4& getProjectionMatrix() const;
    const core::matrix4& getViewMatrix() const;
    core::vector3df getTarget() const;
    core::vector3df getUpVector() const;
    f32 getNearValue() const;
    f32 getFarValue() const;
    f32 getAspectRatio() const;
    f32 getFOV() const;
    const SViewFrustum* getViewFrustum() const;
    ICursorControl* getCursorControl();

    ESCENE_NODE_TYPE getType() const { return ESNT_CAMERA; }
    bool OnEvent(const SEvent& event);
    void render();
    void recalculateViewArea();
    void recalculateProjectionMatrix();
    void move(int dir);
    void rotate(core::vector3df v);

private:
    f32 near, far, aspect, FOV;
    core::matrix4 projectionMatrix, viewMatrix;
    core::vector3df target, upVector;
    SViewFrustum viewFrustrum;
    bool enabled;
    core::aabbox3d<f32> BBox;
    ICursorControl* cursorControl;
    amhEventReceiver* eventReceiver;
    IrrlichtDevice* device;

public:
    amhCameraSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
            const core::vector3df& position = core::vector3df(0,0,0),
            const core::vector3df& rotation = core::vector3df(0,0,0),
            const core::vector3df& scale = core::vector3df(1.0f,1.0f,1.0f));
    ~amhCameraSceneNode(void);
};
#endif

fichier .cpp

Code:

#include "amhCameraSceneNode.h"

// GET FUNCTIONS ---------------------
const core::matrix4& amhCameraSceneNode::getProjectionMatrix() const{
    return projectionMatrix;
}
const core::matrix4& amhCameraSceneNode::getViewMatrix() const{
    return viewMatrix;
}
core::vector3df amhCameraSceneNode::getTarget() const{
    return target;
}
core::vector3df amhCameraSceneNode::getUpVector() const{
    return upVector;
}
f32 amhCameraSceneNode::getNearValue() const{
    return near;
}
f32 amhCameraSceneNode::getFarValue() const{
    return far;
}
f32 amhCameraSceneNode::getAspectRatio() const{
    return aspect;
}
f32 amhCameraSceneNode::getFOV() const{
    return FOV;
}
const SViewFrustum* amhCameraSceneNode::getViewFrustum() const{
    return &viewFrustrum;
}
const core::aabbox3d<f32>& amhCameraSceneNode::getBoundingBox() const{
    return BBox;
}

bool amhCameraSceneNode::isInputReceiverEnabled() const{
    return enabled;
}

ICursorControl* amhCameraSceneNode::getCursorControl(){
    return cursorControl;
}


// MISC FUNCTIONS ----------------------
bool amhCameraSceneNode::OnEvent(const SEvent& event){

    if(event.EventType == EET_MOUSE_INPUT_EVENT){
        core::vector3df v;
        v.Z = 0.0f;
        core::dimension2d<s32> screenSize = device->getVideoDriver()->getScreenSize();
        s32 mWidth = screenSize.Width /2;
        s32 mHeight = screenSize.Height / 2;

        if(event.MouseInput.X >= mWidth + 0.5f){    v.X += 1.0;    }
        if(event.MouseInput.X >= mHeight  + 0.5f){    v.Y += 1.0;    }
        if(event.MouseInput.X <= mWidth - 0.5f){    v.X -= 1.0;    }
        if(event.MouseInput.X <= mHeight  - 0.5f){    v.Y -= 1.0;    }
        
        rotate(v);
        position2d<f32> pos;
        pos.X = screenSize.Width /2.0f;
        pos.Y = screenSize.Height /2.0f;
        cursorControl->setPosition(pos);

        return true;
    }
    if(event.EventType == EET_KEY_INPUT_EVENT){
        eventReceiver->keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
        return true;
    }
    return false;
}
void amhCameraSceneNode::recalculateViewArea()
{
    viewFrustrum.cameraPosition = getAbsolutePosition();
    viewFrustrum.setFrom ( viewFrustrum.Matrices [ SViewFrustum::ETS_VIEW_PROJECTION_3 ] );
}

void amhCameraSceneNode::recalculateProjectionMatrix()
{
    viewFrustrum.Matrices [ video::ETS_PROJECTION ].buildProjectionMatrixPerspectiveFovLH(FOV, aspect, near, far);
    viewFrustrum.setTransformState ( video::ETS_PROJECTION );
}


// SET FUNCTIONS -----------------------
void amhCameraSceneNode::setCursorControl(ICursorControl* icc){
    cursorControl = icc;
    position2d<f32> pos;
    core::dimension2d<s32> screenSize = device->getVideoDriver()->getScreenSize();
    pos.X = screenSize.Width /2.0f;
    pos.Y = screenSize.Height /2.0f;
    cursorControl->setPosition(pos);
}

void amhCameraSceneNode::setDevice(IrrlichtDevice* d){
    device = d;
}

void amhCameraSceneNode::setProjectionMatrix(const core::matrix4& projection){
    this->projectionMatrix = projection;
}

void amhCameraSceneNode::setEventReceiver(amhEventReceiver* ereceiver){
    eventReceiver = ereceiver;
}

void amhCameraSceneNode::setTarget(const core::vector3df& pos){
    target = pos;
}
void amhCameraSceneNode::setUpVector(const core::vector3df& pos){
    upVector = pos;
}
void amhCameraSceneNode::setNearValue(f32 zn){
    near = zn;
}
void amhCameraSceneNode::setFarValue(f32 zf){
    far = zf;
}
void amhCameraSceneNode::setAspectRatio(f32 aspect){
    this->aspect = aspect;
}
void amhCameraSceneNode::setFOV(f32 fovy){
    FOV = fovy;
}
void amhCameraSceneNode::setInputReceiverEnabled(bool enabled){
    this->enabled = enabled;
}
void amhCameraSceneNode::render(){

}

void amhCameraSceneNode::move(int dir){
    core::vector3df newPos;
    if(dir == MOVE_FORWARD)    { newPos.X += 1.0f;    }
    if(dir == MOVE_BACKWARD){ newPos.X -= 1.0f;    }
    if(dir == MOVE_UP)        { newPos.Z += 1.0f;    }
    if(dir == MOVE_DOWN)    { newPos.Z -= 1.0f;    }
    if(dir == MOVE_LEFT)    { newPos.Y += 1.0f;    }
    if(dir == MOVE_RIGHT)    { newPos.Y -= 1.0f; }
    
    setPosition(newPos);
}

void amhCameraSceneNode::rotate(core::vector3df v){
    setRotation(v);
}

amhCameraSceneNode::amhCameraSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id,
        const core::vector3df& position, const core::vector3df& rotation ,
        const core::vector3df& scale)
            : ICameraSceneNode(parent, mgr, id, core::vector3df(0.0f,0.0f,0.0f), 
                                                core::vector3df(0.0f,0.0f,0.0f), 
                                                core::vector3df(1.0f,1.0f,1.0f)),
    near(0.1f), 
    far(100000.0f),
    enabled(true),
    FOV(0.75f),
    upVector(0.0f,0.0f,1.0f), target(1.0f, 0.0f, 0.0f){
    video::IVideoDriver* d = mgr->getVideoDriver();
    if (d)
        aspect = (f32)d->getCurrentRenderTargetSize().Width /
            (f32)d->getCurrentRenderTargetSize().Height;

    recalculateProjectionMatrix();
    recalculateViewArea();
}

amhCameraSceneNode::~amhCameraSceneNode(void)
{
}

Hors ligne


Options Liens officiels Caractéristiques Statistiques Communauté
Corrections
irrlicht
irrklang
irredit
irrxml
xhtml 1.0
css 2.1
Propulsé par FluxBB
Traduit par FluxBB.fr
882 membres
1429 sujets
11119 messages
Dernier membre inscrit: LiseBuisson96
94 invités en ligne
Aucun membre connecté
RSS Feed