Page 1 of 2

Wow Camera

Posted: Mon May 08, 2006 10:44 pm
by juliusctw
Hello here is the source for the wow camera i promised

video of what it does
http://video.google.com/videoplay?docid ... 72&q=chieh

I will post the source code when i'm done cleaning up

Posted: Sun Jun 04, 2006 9:56 pm
by Havok
delete

hello

Posted: Mon Jun 05, 2006 6:29 am
by juliusctw
hello

I am in the process of writing it exactly like fps in irrlicht, so you'll just instantiate the class with the scene that it follows, i'll update you when it comes out.

code

Posted: Tue Jun 06, 2006 2:07 am
by Wuzit
Wheres the actual code for WowCamera?

i took it out

Posted: Tue Jun 06, 2006 3:17 am
by juliusctw
I took it out cus i'm working on a much better one

Posted: Wed Jun 14, 2006 4:10 am
by XFactor
nice work, i cant wait till you release the code, keep up the good work

Posted: Tue Jul 11, 2006 3:26 am
by juliusctw
Hello

The wow camera i had before was really sloppy, i have since then cleaned it us into one camera class. Basically, all you need to do is instantiate it, and it would just work.

So this is a third person camera that you attach a sceneNode to, once it is attached you can press s d f e to move it , w and r to rotate it, the camera would follow, you can also zoom in and out by scrolling the wheel, the right mouse button would rotate the sceneNode and the left would move the camera in a spherical fashion around the sceneNode,

the camera is called IamarCamera since I am building it for my newly found company Iamar , there are no animation bindings so the object doesn't animate it only translates, this is mainly because we have so many different mesh formats , in the future I will write one for MD2 format. You can find it now on my personal website

http://www.freewebs.com/juliusctw/

This is done in linux, so you might have to tweek it a little for window users, the following is how the main.cpp would look like using IamarCamera




//*******************************

#include <irrlicht.h>
#include "IamarCamera.h"

using namespace irr;



#pragma comment(lib, "Irrlicht.lib")


class MyEventReceiver : public IEventReceiver
{
public:

MyEventReceiver(scene::ISceneNode* terrain)
{
}

bool OnEvent(SEvent event)
{

return false;
}

private:
scene::ISceneNode* Terrain;
};

//* you don't really need the receiver, the camer would work with out it

int main()
{
// create device
IrrlichtDevice* device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(1024, 768));

if (device == 0)
return 1; // could not create selected driver.

video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* env = device->getGUIEnvironment();

driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);

// add Iamar logo
env->addImage(driver->getTexture("logo.png"),
core::position2d<s32>(-40,-40));

// add some help text
gui::IGUIStaticText* text = env->addStaticText(
L"Press 's d f e w r' for movement",
core::rect<s32>(10,453,200,475), true, true, 0, -1, true);



scene::IAnimatedMeshSceneNode* anms = smgr->addAnimatedMeshSceneNode(
smgr->getMesh("../../media/sydney.md2"));

if (anms)
{
anms->setMaterialFlag(video::EMF_LIGHTING, false);

anms->setMD2Animation(scene::EMAT_RUN);
anms->setFrameLoop(320, 367);
anms->setAnimationSpeed(80);
anms->setPosition(core::vector3df(1900*2,255*2,3700*2));

anms->setRotation(core::vector3df(0,180.0f,0));
anms->setMaterialTexture(0, driver->getTexture("../../media/sydney.bmp"));
}




// add camera
// This is the only part required to use this camera
// besides the headers.
// important ::::::::::::::::::::::::::::::::::::::::::::::
//
//
//
scene::IamarCamera* Icamera;
Icamera = new scene::IamarCamera((scene::ISceneNode*)anms, smgr, -1);
smgr->setActiveCamera(Icamera);

// important ::::::::::::::::::::::::::::::::::::::::::::::






// add terrain scene node
scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
"../../media/terrain-heightmap.bmp");

terrain->setScale(core::vector3df(40, 4.4f, 40));
terrain->setMaterialFlag(video::EMF_LIGHTING, false);

terrain->setMaterialTexture(0, driver->getTexture("../../media/terrain-texture.jpg"));
terrain->setMaterialTexture(1, driver->getTexture("../../media/detailmap3.jpg"));

terrain->setMaterialType(video::EMT_DETAIL_MAP);

terrain->scaleTexture(10.0f, 20.0f);


// create triangle selector for the terrain
scene::ITriangleSelector* selector
= smgr->createTerrainTriangleSelector(terrain, 0);
terrain->setTriangleSelector(selector);
selector->drop();

// create event receiver
MyEventReceiver receiver(terrain);
device->setEventReceiver(&receiver);

// create skybox
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);

smgr->addSkyBoxSceneNode(
driver->getTexture("../../media/irrlicht2_up.jpg"),
driver->getTexture("../../media/irrlicht2_dn.jpg"),
driver->getTexture("../../media/irrlicht2_lf.jpg"),
driver->getTexture("../../media/irrlicht2_rt.jpg"),
driver->getTexture("../../media/irrlicht2_ft.jpg"),
driver->getTexture("../../media/irrlicht2_bk.jpg"));

driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);

/*
That's it, draw everything. Now you know how to use terrain in Irrlicht.
*/

int lastFPS = -1;

while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, 0 );

smgr->drawAll();
env->drawAll();

driver->endScene();

// display frames per second in window title
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Terrain Renderer - Irrlicht Engine [";
str += driver->getName();
str += "] FPS:";
str += fps;

device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}

device->drop();

return 0;
}

Posted: Sun Jul 16, 2006 7:43 pm
by n_u_n_u
Excuse me how did you get "IamarCamera.h" from? :(

Posted: Sun Jul 16, 2006 7:52 pm
by n_u_n_u
Oh I found it...

Posted: Fri Jul 21, 2006 10:17 am
by herion
If you want quite smooth, Gothic-like camera from my old project - Blood Giver { http://members.lycos.nl/nadro/download/irrdemo.zip }, you can find the source in following file:

Code: Select all

#ifndef _GAM_IRRCAMERA_H_
#define _GAM_IRRCAMERA_H_

class IrrTPPCameraSceneNode 
{
public:
	ICameraSceneNode *camera;
	float xrot;
	float zrot;
	float deltax;
	float deltay;
	IAnimatedMeshSceneNode *tnode;
	vector3df pos;

	void doCameraDoing();
};

////////////////////////////////////////////////////////////////////

void IrrTPPCameraSceneNode::doCameraDoing()
{
    core::position2d<f32> cursorPos = irrDevice->getCursorControl()->getRelativePosition();
     scene::ICameraSceneNode* camera = irrDevice->getSceneManager()->getActiveCamera();
     core::vector3df cameraPos = camera->getAbsolutePosition();

	 float the__faktor=25/(theFps*5);
//	 if (the__faktor>1) the__faktor=1;


	 if (deltax>0)
	 deltax-=deltax*the__faktor;
	 if (deltax<0)
	 deltax-=deltax*the__faktor;

	 if (deltay>0)
	 deltay-=deltay*the__faktor;
	 if (deltay<0)
	 deltay-=deltay*the__faktor;


	 float deltamx=( cursorPos.X - 0.5f )*12;
	 float deltamy=( cursorPos.Y - 0.5f )*12;

	 
     
     deltax += deltamx;
     deltay += deltamy;
	 


	 float limit=((70/theFps)*2.8f);

	 if (deltax>limit) deltax=limit;
	 if (deltay>limit) deltay=limit;
	 if (deltax<-limit) deltax=-limit;
	 if (deltay<-limit) deltay=-limit;
	 

     xrot += deltax;
     zrot -= deltay;

     if( zrot <-69 )
         zrot = -69;
     else
     if( zrot > 69 )
         zrot = 69;
     irrDevice->getCursorControl()->setPosition( 0.5f, 0.5f );
     
     core::vector3df playerPos = tnode->getPosition();
     
 //    float xf = playerPos.X - cos( direction * PI / 180.0f ) * 3.4f;
     float yf = playerPos.Y - sin( zrot * PI / 180.0f ) * 30;
  //   float zf = playerPos.Z + sin( direction * PI / 180.0f ) * 3.4f;

	 float  xf = playerPos.X - cos( zrot * irr::core::PI / 180.0f ) * cos( (xrot) * irr::core::PI / 180.0f ) * 1;
     float  zf = playerPos.Z + cos( zrot * irr::core::PI / 180.0f ) * sin( (xrot )* irr::core::PI / 180.0f ) * 1; 
	 

	 vector3df   Result;
	 vector3df   Shorty=vector3df(xf, yf, zf);
	 vector3df shortyNorm=Shorty;
	 shortyNorm=Shorty-playerPos;
	triangle3df   Triangle;
	line3d<f32>   Ray;
   

	playerPos.Y+=8;
	Ray.start=playerPos;
	bool falling=false;
	Ray.end=Shorty;
   
   irrSceneMgr->getSceneCollisionManager()->getCollisionPoint(Ray, map_triangleselector, Result, Triangle);

     if (Result==vector3df(0,0,0)) Result=Shorty;

	 Result= irrSceneMgr->getSceneCollisionManager()->getCollisionResultPosition(
		 map_triangleselector, 
		 playerPos, 
		 vector3df(2,2,2), 
		 Result-playerPos, 
		 Triangle,
		 falling,
		 0.02f,
		 vector3df(0,0,0));


     camera->setPosition( Result );
	 // glowa kolesia
     camera->setTarget( core::vector3df( playerPos.X, playerPos.Y, playerPos.Z ) );

	 tnode->setRotation( core::vector3df( 0, xrot+90, 0 ) );

	 if (gracz.moving)
	 {
		 tnode->setRotation( core::vector3df( 0, xrot+90+(deltax*9), 0 ) );
	 }

}



IrrTPPCameraSceneNode zenon;


#endif

It's quite old and it was written for me only, so it's ugly... { i've run it on irr 0.12 }

i run on linux

Posted: Sun Jul 23, 2006 8:51 pm
by juliusctw
hello

i run on linux, i can't open up the exe

Posted: Sun Jul 23, 2006 9:13 pm
by hybrid
Then use wine.

thanks, i just got wine working

Posted: Mon Jul 24, 2006 1:07 pm
by juliusctw
thanks hybrid, i just got wine working, its pretty good


herion:
i ran your program, but it doesn't seem to let me enter when i click on the top option, it just goes to a blue screen with some sound, the second option shows me some instruction, and the last one exits , unless wine is not working, i'm not sure what's going on there

Posted: Mon Jul 24, 2006 2:19 pm
by herion
Directx 9.0c is required... and quite good graph. card { 64MB at least } I think some older version would crash.

that's obviously not going to work

Posted: Tue Jul 25, 2006 2:57 am
by juliusctw
i guess that's the problem

i'm using wine on linux, i don't have directx9 , thanx

do you mind if i play around with some of your mesh? I 'm getting really bored with sydney and faerie