blind custom camera

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
acropole
Posts: 17
Joined: Tue Feb 08, 2005 2:59 am
Contact:

blind custom camera

Post by acropole »

Hi,

I'm building a new camera (without gimball lock).
Everthing compile fine and the game run fine too, but nothing is rendered (except GUI before creation of my camera).
It works fine with irrlicht's FPS camera. So it's not a problem in the map, map loading or anything else.

My class :

h file

Code: Select all

#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
cpp file :

Code: Select all

#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.0001f), 
	far(100000.0f),
	enabled(true),
	FOV(1.0f),
	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)
{
}
thanks for your help !
Gogolian
Posts: 32
Joined: Sat May 17, 2008 10:49 pm

Post by Gogolian »

maybe i am wrong, but aren't you overriding render() function of ICameraSceneNode with empty func?
And the darkness begun...
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

At some point you need to apply your projection and view matrices to the driver. The FPS camera does this in CCameraSceneNode::render().
Post Reply