Wow Camera
-
- Posts: 11
- Joined: Sat Jul 15, 2006 5:42 am
i'm not sure what you mean
hello
i'm not sure exactly what you mean, i have 2 camera classes, the fist one doesn't animate the character, and the second one animates the MD2 characters for you.
Since you are asking for animation, i guess you got the first one, i suggest you try the second one and if it doesn't meet your needs, then try to customize your own, the source code to animate anything is on the second one.
i'm not sure exactly what you mean, i have 2 camera classes, the fist one doesn't animate the character, and the second one animates the MD2 characters for you.
Since you are asking for animation, i guess you got the first one, i suggest you try the second one and if it doesn't meet your needs, then try to customize your own, the source code to animate anything is on the second one.
irrlicht game character project
http://picasaweb.google.com/juliusctw/FinishedArt
http://picasaweb.google.com/juliusctw/FinishedArt
herion
hey herion
i finally got around to your game, i really like it, but i'm not sure how you deal with such a big terrain, everytime i use a terrain plus collision, it really kills my frame rate, to the point that i have to use a flat terrain, the way i have generated the terrain is exactly the same way as the tutorial, so i don't think there something wrong i have done.
the terrain is really sucking up a lot of frame rate, i really don't want to create my own terrain scene node
i finally got around to your game, i really like it, but i'm not sure how you deal with such a big terrain, everytime i use a terrain plus collision, it really kills my frame rate, to the point that i have to use a flat terrain, the way i have generated the terrain is exactly the same way as the tutorial, so i don't think there something wrong i have done.
the terrain is really sucking up a lot of frame rate, i really don't want to create my own terrain scene node
irrlicht game character project
http://picasaweb.google.com/juliusctw/FinishedArt
http://picasaweb.google.com/juliusctw/FinishedArt
-
- Posts: 1029
- Joined: Thu Apr 06, 2006 12:45 am
- Location: Tennesee, USA
- Contact:
tell me the error you got
Hello
can you tell me the error you got, i didn't get any errors when i switched to 1.1, i wrote the camera class specifically in linux, so perhaps there's some changes i didn't notice.
I will rewrite the whole thing in windows in the future, but that's not for a while, not until i finished an alpha version of my game in linux, so i suggest you work other aspects of your game, i'll post it when i fixed it.
can you tell me the error you got, i didn't get any errors when i switched to 1.1, i wrote the camera class specifically in linux, so perhaps there's some changes i didn't notice.
I will rewrite the whole thing in windows in the future, but that's not for a while, not until i finished an alpha version of my game in linux, so i suggest you work other aspects of your game, i'll post it when i fixed it.
irrlicht game character project
http://picasaweb.google.com/juliusctw/FinishedArt
http://picasaweb.google.com/juliusctw/FinishedArt
definitely a problem with windows
definitely a problem with windows
sorry about that, but when my project comes out, it would be compatible with windows, you'd be able to use my project directly, but that's some times
sorry about that, but when my project comes out, it would be compatible with windows, you'd be able to use my project directly, but that's some times
irrlicht game character project
http://picasaweb.google.com/juliusctw/FinishedArt
http://picasaweb.google.com/juliusctw/FinishedArt
Could you post errors you're getting? (If it's type errors please just post 1 instead of duplicates so we can post a solution and you can apply it to all the lines you get an error on). I don't have the capability of compiling it myself on this machine, might try for you later, for now this would be quickest.Sidus wrote:Hello, im learning c++..
Can't get it work with Irrlicht 1.7.1, could anyone updating the code?
Thanks so much
Also, let's hope mods don't mind you resurrecting a 4 year old thread
if (msg.getRubbishFactor() > rubbishLimit) { ignorePost(); cout << how it should be done << "\n"; }
Any kind of errors, list is too much long...kingdutch wrote:Could you post errors you're getting? (If it's type errors please just post 1 instead of duplicates so we can post a solution and you can apply it to all the lines you get an error on). I don't have the capability of compiling it myself on this machine, might try for you later, for now this would be quickest.Sidus wrote:Hello, im learning c++..
Can't get it work with Irrlicht 1.7.1, could anyone updating the code?
Thanks so much
Also, let's hope mods don't mind you resurrecting a 4 year old thread
Still a alternative of a 3rd person camera compatible with Irrlicht 1.7?
Tried to upgrading it but missing where im wrong:
IamarCamera.h
IamarCamera.cpp
IamarCamera.h
Code: Select all
// Copyright (C) 2002-2006 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __IAMAR_CAMERA_H__
#define __IAMAR_CAMERA_H__
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
class IamarCamera : public ICameraSceneNode
{
public:
//! constructor
IamarCamera(ISceneNode* parent, ISceneManager* smgr, s32 id,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& lookat = core::vector3df(0,0,100));
//! destructor
virtual ~IamarCamera();
//Events
virtual void render();
virtual bool OnEvent(const SEvent& event);
virtual void OnRegisterSceneNode();
//Setup
virtual void setInputReceiverEnabled(bool enabled);
virtual bool isInputReceiverEnabled() const;
//Gets
virtual const aabbox3d<f32>& getBoundingBox() const;
virtual const matrix4& getProjectionMatrix() const;
virtual const SViewFrustum* getViewFrustum() const;
virtual const core::vector3df& getTarget() const;
virtual const matrix4& getViewMatrix() const;
virtual const core::vector3df& getUpVector() const;
virtual f32 getNearValue() const;
virtual f32 getFarValue() const;
virtual f32 getAspectRatio() const;
virtual f32 getFOV() const;
//Sets
virtual void setNearValue(f32 zn);
virtual void setFarValue(f32 zf);
virtual void setAspectRatio(f32 aspect);
virtual void setFOV(f32 fovy);
virtual void setUpVector(const vector3df& pos);
virtual void setProjectionMatrix(const matrix4& projection);
virtual void setTarget(const vector3df& newpos);
virtual void setRotation(const irr::core::vector3df &) {}
virtual void setProjectionMatrix(const irr::core::matrix4 &,bool) {}
virtual void setViewMatrixAffector(const irr::core::matrix4 &) {}
virtual const core::matrix4& getViewMatrixAffector() const {return core::matrix4();};
virtual void bindTargetAndRotation(bool) {}
virtual bool getTargetAndRotationBinding() const {return 0;}
virtual ESCENE_NODE_TYPE getType() { return ESNT_CAMERA; }
void calculateCameraPosition();
protected:
int wheelSpeed;
float radius;
float alpha;
float theta, Ttheta;
float xMovementMult, yMovementMult;
typedef enum
{
PRESSING_DOWN = 0,
PRESSED_DOWN,
RELEASING,
RELEASED
}key_state;
key_state wkey, skey, ekey, dkey, rkey, fkey;
typedef struct MouseClick {
s32 x, y;
key_state mouse_key;
}MouseClick; //Mouse being held states
MouseClick LeftMouseClick, RightMouseClick;
float initial_mousePos_x, initial_mousePos_y;
int keyUpdate(SEvent, key_state);
void recalculateProjectionMatrix();
void recalculateViewArea();
scene::ISceneNode* Parent;
//core::vector3df Pos;
vector3df Target;
vector3df UpVector;
matrix4 Projection;
matrix4 View;
core::aabbox3d<f32> BBox;
f32 fovy; // Field of view, in radians.
f32 aspect; // Aspect ratio.
f32 zn; // value of the near view-plane.
f32 zf; // Z-value of the far view-plane.
core::dimension2d<f32> screenDim;
SViewFrustum ViewArea;
bool InputReceiverEnabled;
};
#endif
Code: Select all
#include "IamarCamera.h"
//! constructor
IamarCamera::IamarCamera(ISceneNode* parent, ISceneManager* mgr, s32 id,
const core::vector3df& position, const core::vector3df& lookat)
: ICameraSceneNode(parent, mgr, id, position, core::vector3df(-40.0f, 0.0f, -40.0f),
core::vector3df(0.0f, 0.0f, 0.0f)), InputReceiverEnabled(true)
{
Parent = parent;
wheelSpeed = 5;
radius = 20;
alpha = 20;
theta = 180;
Ttheta = theta;
LeftMouseClick.mouse_key = RELEASED;
RightMouseClick.mouse_key = RELEASED;
ekey = RELEASED;
wkey = RELEASED;
dkey = RELEASED;
fkey = RELEASED;
skey = RELEASED;
rkey = RELEASED;
xMovementMult = 0.1;
yMovementMult = 0.1;
BBox.reset(0,0,0);
// set default view
UpVector.set(0.0f, 1.0f, 0.0f);
calculateCameraPosition();
// set default projection
fovy = core::PI / 2.5f; // Field of view, in radians.
aspect = 4.0f / 3.0f; // Aspect ratio.
zn = 1.0f; // value of the near view-plane.
zf = 3000.0f; // Z-value of the far view-plane.
video::IVideoDriver* d = mgr->getVideoDriver();
if (d)
{
screenDim.Width = (f32)d->getScreenSize().Width;
screenDim.Height = (f32)d->getScreenSize().Height;
aspect = screenDim.Height / screenDim.Width;
}
recalculateProjectionMatrix();
}
//! destructor
IamarCamera::~IamarCamera()
{
}
void IamarCamera::setInputReceiverEnabled(bool enabled)
{
InputReceiverEnabled = enabled;
}
bool IamarCamera::isInputReceiverEnabled() const
{
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return InputReceiverEnabled;
}
void IamarCamera::setProjectionMatrix(const matrix4& projection)
{
Projection = projection;
}
const matrix4& IamarCamera::getProjectionMatrix() const
{
return Projection;
}
const matrix4& IamarCamera::getViewMatrix() const
{
return View;
}
bool IamarCamera::OnEvent(const SEvent& event)
{
core::vector3df vect;
float PI = 3.1415;
if (event.EventType == EET_MOUSE_INPUT_EVENT)
{
switch(event.MouseInput.Event)
{
case EMIE_MOUSE_WHEEL:
{
if (event.MouseInput.Wheel > 0)
{
radius -= wheelSpeed;
if (radius < 5)
radius = 5;
}
else
{
radius += wheelSpeed;
if (radius > 400)
radius = 400;
}
calculateCameraPosition();
}
break;
case EMIE_MOUSE_MOVED:
{
//**************** Right Mouse
//
if (RightMouseClick.mouse_key == PRESSED_DOWN)
{
float xMovement = event.MouseInput.X - RightMouseClick.x;
Ttheta -= xMovement*xMovementMult;
if(Ttheta < 0)
Ttheta = 360 + Ttheta;
if (Ttheta>360)
Ttheta = Ttheta - 360;
vect = Parent->getRotation();
vect.Y = 360-Ttheta;
Parent->setRotation(vect);
theta = 180;
float yMovement = event.MouseInput.Y - RightMouseClick.y;
alpha += yMovement*yMovementMult;
if (alpha < -45)
alpha = -45;
if (alpha > 90)
alpha = 90;
RightMouseClick.x = event.MouseInput.X;
RightMouseClick.y = event.MouseInput.Y;
calculateCameraPosition();
}
//**************** Left Mouse
//
if (LeftMouseClick.mouse_key == PRESSED_DOWN)
{
float xMovement = event.MouseInput.X - LeftMouseClick.x;
theta -= xMovement*yMovementMult;
if(theta < 0)
theta = 360 + theta;
if (theta>360)
theta = theta - 360;
float yMovement = event.MouseInput.Y - LeftMouseClick.y;
alpha += yMovement*yMovementMult;
if (alpha < -45)
alpha = -45;
if (alpha > 90)
alpha = 90;
LeftMouseClick.x = event.MouseInput.X;
LeftMouseClick.y = event.MouseInput.Y;
calculateCameraPosition();
}
}
break;
case EMIE_RMOUSE_PRESSED_DOWN:
{
if (RightMouseClick.mouse_key == RELEASING)
{
RightMouseClick.x = event.MouseInput.X;
RightMouseClick.y = event.MouseInput.Y;
RightMouseClick.mouse_key = PRESSING_DOWN;
}
if (RightMouseClick.mouse_key == RELEASED)
{
RightMouseClick.x = event.MouseInput.X;
RightMouseClick.y = event.MouseInput.Y;
RightMouseClick.mouse_key = PRESSING_DOWN;
}
if (RightMouseClick.mouse_key == PRESSING_DOWN)
RightMouseClick.mouse_key = PRESSED_DOWN;
if (RightMouseClick.mouse_key == PRESSED_DOWN){}
}
break;
case EMIE_RMOUSE_LEFT_UP:
{
if (RightMouseClick.mouse_key == RELEASING)
RightMouseClick.mouse_key = RELEASED;
if (RightMouseClick.mouse_key == RELEASED){}
if (RightMouseClick.mouse_key == PRESSING_DOWN)
RightMouseClick.mouse_key = RELEASING;
if (RightMouseClick.mouse_key == PRESSED_DOWN)
RightMouseClick.mouse_key = RELEASING;
}
break;
case EMIE_LMOUSE_PRESSED_DOWN:
if (LeftMouseClick.mouse_key == RELEASING)
{
LeftMouseClick.x = event.MouseInput.X;
LeftMouseClick.y = event.MouseInput.Y;
LeftMouseClick.mouse_key = PRESSING_DOWN;
}
if (LeftMouseClick.mouse_key == RELEASED)
{
LeftMouseClick.x = event.MouseInput.X;
LeftMouseClick.y = event.MouseInput.Y;
LeftMouseClick.mouse_key = PRESSING_DOWN;
}
if (LeftMouseClick.mouse_key == PRESSING_DOWN)
LeftMouseClick.mouse_key = PRESSED_DOWN;
if (LeftMouseClick.mouse_key == PRESSED_DOWN){}
break;
case EMIE_LMOUSE_LEFT_UP:
if (LeftMouseClick.mouse_key == RELEASING)
LeftMouseClick.mouse_key = RELEASED;
if (LeftMouseClick.mouse_key == RELEASED){}
if (LeftMouseClick.mouse_key == PRESSING_DOWN)
LeftMouseClick.mouse_key = RELEASING;
if (LeftMouseClick.mouse_key == PRESSED_DOWN)
LeftMouseClick.mouse_key = RELEASING;
break;
default: break;
}
}
//editing here
if (event.EventType == EET_KEY_INPUT_EVENT)
{
if (event.KeyInput.Key == KEY_KEY_E)
ekey = (key_state)keyUpdate(event, ekey);
if (event.KeyInput.Key == KEY_KEY_W)
wkey = (key_state)keyUpdate(event, wkey);
if (event.KeyInput.Key == KEY_KEY_S)
skey = (key_state)keyUpdate(event, skey);
if (event.KeyInput.Key == KEY_KEY_D)
dkey = (key_state)keyUpdate(event, dkey);
if (event.KeyInput.Key == KEY_KEY_R)
rkey = (key_state)keyUpdate(event, rkey);
if (event.KeyInput.Key == KEY_KEY_F)
fkey = (key_state)keyUpdate(event, fkey);
core::vector3df R = Parent->getRotation();
}
return false;
}
void IamarCamera::setTarget(const core::vector3df& pos)
{
Target = pos;
}
const core::vector3df& IamarCamera::getTarget() const
{
return Target;
}
void IamarCamera::setUpVector(const vector3df& pos)
{
UpVector = pos;
}
const core::vector3df& IamarCamera::getUpVector() const
{
return UpVector;
}
f32 IamarCamera::getNearValue() const
{
return zn;
}
f32 IamarCamera::getFarValue() const
{
return zf;
}
f32 IamarCamera::getAspectRatio() const
{
return aspect;
}
f32 IamarCamera::getFOV() const
{
return fovy;
}
void IamarCamera::setNearValue(f32 f)
{
zn = f;
recalculateProjectionMatrix();
}
void IamarCamera::setFarValue(f32 f)
{
zf = f;
recalculateProjectionMatrix();
}
void IamarCamera::setAspectRatio(f32 f)
{
aspect = f;
recalculateProjectionMatrix();
}
void IamarCamera::setFOV(f32 f)
{
fovy = f;
recalculateProjectionMatrix();
}
void IamarCamera::recalculateProjectionMatrix()
{
Projection.buildProjectionMatrixPerspectiveFovLH(fovy, aspect, zn, zf);
//recalculateViewArea();
}
void IamarCamera::OnRegisterSceneNode()
{
float xTrans, yTrans;
float PI = 3.1415;
core::vector3df R = Parent->getRotation();
R.Y = R.Y - 180;
if ((ekey == PRESSING_DOWN) || (ekey == PRESSED_DOWN))
{
xTrans = 5*cos(R.Y*PI/180.0);
yTrans = 5*sin(R.Y*PI/180.0);
core::vector3df v = Parent->getPosition();
v.X = v.X - xTrans;
v.Z = v.Z + yTrans;
Parent->setPosition(v);
v.Y = v.Y + 30;
Target = v;
Parent->updateAbsolutePosition();
updateAbsolutePosition();
}
if ((dkey == PRESSING_DOWN) || (dkey == PRESSED_DOWN))
{
xTrans = 5*cos(R.Y*PI/180.0);
yTrans = 5*sin(R.Y*PI/180.0);
core::vector3df v = Parent->getPosition();
v.X = v.X + xTrans;
v.Z = v.Z - yTrans;
Parent->setPosition(v);
v.Y = v.Y + 30;
Target = v;
Parent->updateAbsolutePosition();
updateAbsolutePosition();
}
if ((skey == PRESSING_DOWN) || (skey == PRESSED_DOWN))
{
xTrans = 5*cos(R.Y*PI/180.0);
yTrans = 5*sin(R.Y*PI/180.0);
core::vector3df v = Parent->getPosition();
v.X = v.X + yTrans;
v.Z = v.Z - xTrans;
Parent->setPosition(v);
v.Y = v.Y + 30;
Target = v;
Parent->updateAbsolutePosition();
updateAbsolutePosition();
}
if ((fkey == PRESSING_DOWN) || (fkey == PRESSED_DOWN))
{
xTrans = 5*cos(R.Y*PI/180.0);
yTrans = 5*sin(R.Y*PI/180.0);
core::vector3df v = Parent->getPosition();
v.X = v.X - yTrans;
v.Z = v.Z + xTrans;
Parent->setPosition(v);
v.Y = v.Y + 30;
Target = v;
Parent->updateAbsolutePosition();
updateAbsolutePosition();
}
if ((wkey == PRESSING_DOWN) || (wkey == PRESSED_DOWN))
{
core::vector3df R = Parent->getRotation();
R.Y = R.Y - 0.3;
Parent->setRotation(R);
Parent->updateAbsolutePosition();
updateAbsolutePosition();
}
if ((rkey == PRESSING_DOWN) || (rkey == PRESSED_DOWN))
{
core::vector3df R = Parent->getRotation();
R.Y = R.Y + 0.3;
Parent->setRotation(R);
Parent->updateAbsolutePosition();
updateAbsolutePosition();
}
video::IVideoDriver* driver = SceneManager->getVideoDriver();
if (!driver)
return;
if (SceneManager->getActiveCamera() == this)
{
screenDim.Width = (f32)driver->getScreenSize().Width;
screenDim.Height = (f32)driver->getScreenSize().Height;
driver->setTransform(video::ETS_PROJECTION, Projection);
// if upvector and vector to the target are the same, we have a
// problem. so solve this problem:
core::vector3df pos = getAbsolutePosition();
core::vector3df tgtv = Target - pos;
tgtv.normalize();
core::vector3df up = UpVector;
up.normalize();
f32 dp = tgtv.dotProduct(up);
if ((dp > -1.0001f && dp < -0.9999f) ||
(dp < 1.0001f && dp > 0.9999f))
up.X += 1.0f;
View.buildCameraLookAtMatrixLH(pos, Target, up);
recalculateViewArea();
SceneManager->registerNodeForRendering(this, ESNRP_LIGHT);
}
ISceneNode::OnRegisterSceneNode();
}
void IamarCamera::render()
{
video::IVideoDriver* driver = SceneManager->getVideoDriver();
if (!driver)
return;
driver->setTransform(video::ETS_VIEW, View);
}
const aabbox3d<f32>& IamarCamera::getBoundingBox() const
{
return BBox;
}
const SViewFrustum* IamarCamera::getViewFrustum() const
{
return &ViewArea;
}
void IamarCamera::recalculateViewArea()
{
core::matrix4 mat = Projection * View;
ViewArea = SViewFrustum(mat);
ViewArea.cameraPosition = getAbsolutePosition();
ViewArea.recalculateBoundingBox();
}
void IamarCamera::calculateCameraPosition()
{
float x,y,z;
float PI = 3.1415;
x = radius*cos(alpha*PI/180)*cos(theta*PI/180);
y = radius*sin(alpha*PI/180);
z = radius*cos(alpha*PI/180)*sin(theta*PI/180);
core::vector3df pos(x, y + 30, z);
core::vector3df character_pos = Parent->getPosition();
character_pos.Y = character_pos.Y + 30;
// printf("cx %f\n", character_pos.X);
// printf("xy %f\n",character_pos.Y);
// printf("cz %f\n", character_pos.Z);
//
// printf("x %f\n",x);
// printf("y %f\n",y);
// printf("z %f\n",z);
//
setPosition(pos);
setTarget(character_pos);
// updateAbsolutePosition();
}
int IamarCamera::keyUpdate( SEvent event, key_state key )
{
if (event.EventType == EET_KEY_INPUT_EVENT)
{
if(event.KeyInput.PressedDown)
{
if (key == RELEASING)
key = PRESSING_DOWN;
if (key == RELEASED)
key = PRESSING_DOWN;
if (key == PRESSING_DOWN)
key = PRESSED_DOWN;
if (key == PRESSED_DOWN){}
}
if(!event.KeyInput.PressedDown)
{
if (key == RELEASING)
key = RELEASED;
if (key == RELEASED){}
if (key == PRESSING_DOWN)
key = RELEASING;
if (key == PRESSED_DOWN)
key = RELEASING;
}
}
return (int)key;
}