(C++) RTSCamera

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
CmdKewin
Posts: 29
Joined: Thu Aug 17, 2006 1:49 pm

Post by CmdKewin »

Ico wrote:Quite interesting - maybe you could add three things (shouldn't be that hard to do at all :) ) so it's "ready out of the box":

Add a bounding box that limits the camera's movement (ignored if set to the default NULL; min/max zoom defined by bounding box too?).
Bounding Box is there. I just need to figure out why it doesn't work properly with the CollisionManager :)
Ico wrote: Add members to control the keys/mousebutton config.
W.I.P. On my current SVN, they are configured through an XML file.
Ico wrote: Maybe add the possibility to drag the map (or better the camera) by (i.e.) holding the right mouse button and dragging the cursor.
Already does that. ;) [shameless plug]I didn't go in the "best code snippets of 2006" for nothing, you know :P [/shameless plug]
Hirogen
Posts: 19
Joined: Tue May 29, 2007 5:55 am

Problem with mouse wheel

Post by Hirogen »

The RTSCamera works fine in my program except of the fact that I cannot zoom with the mouse wheel. Zooming with the two buttons works.
I don't know if it's a problem of my program or of the RTSCamera.
Can you tell my if this function works with your programs?
Konstantin
Posts: 12
Joined: Fri May 18, 2007 3:06 pm
Location: Panketal, Germany

Post by Konstantin »

Good Work, Comander!

But the Camera seems to be a bit to hectic even with a real large map.
Namek Kural
Posts: 81
Joined: Sun Sep 09, 2007 7:01 pm
Location: BW, Germany

Post by Namek Kural »

Thanks! Great Work!

If you want to use it with irrlicht 1.4 you have to insert some "const" and it works perfectly!

@Konstantin: You have to "setZoomSpeed", "setTranslateSpeed" or "setRotationSpeed".

This is a must-have extension to irrlicht! :D
Yustme
Posts: 107
Joined: Sat Dec 01, 2007 10:50 pm

Post by Yustme »

Hi,

I was wondering what an RTSCamera is?

It looks great!
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Last time I've checked RTS was: Real Time Strategy.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

MasterGod wrote:Last time I've checked RTS was: Real Time Strategy.
It means a third-person camera positioned high beneath the terrain looking at the characters/buildings down there. The camera won't be affected by the activities down there unless you've selected a particular group of characters.
renegadeandy
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland
Contact:

Post by renegadeandy »

Hi!

I am using Irrlicht version 1.4 and am getting the following errors on compiling when trying to create a new RTSCamera object :

main.cpp:67: error: cannot allocate an object of type `RTSCamera'

main.cpp:67: error: because the following virtual functions are abstract:

C:/irrlicht-1.4/irrlicht-1.4/include/ICameraSceneNode.h:47: error: virtual const irr::core::matrix4& irr::scene::ICameraSceneNode::getProjectionMatrix() const

C:/irrlicht-1.4/irrlicht-1.4/include/ICameraSceneNode.h:51: error: virtual const irr::core::matrix4& irr::scene::ICameraSceneNode::getViewMatrix() const

C:/irrlicht-1.4/irrlicht-1.4/include/ICameraSceneNode.h:79: error: virtual irr::f32 irr::scene::ICameraSceneNode::getNearValue() const

C:/irrlicht-1.4/irrlicht-1.4/include/ICameraSceneNode.h:83: error: virtual irr::f32 irr::scene::ICameraSceneNode::getFarValue() const

C:/irrlicht-1.4/irrlicht-1.4/include/ICameraSceneNode.h:87: error: virtual irr::f32 irr::scene::ICameraSceneNode::getAspectRatio() const

C:/irrlicht-1.4/irrlicht-1.4/include/ICameraSceneNode.h:91: error: virtual irr::f32 irr::scene::ICameraSceneNode::getFOV() const

C:/irrlicht-1.4/irrlicht-1.4/include/ICameraSceneNode.h:120: error: virtual bool irr::scene::ICameraSceneNode::isInputReceiverEnabled() const

I am using the latest code posted in the thread - please help me out here and hopefully I can get this working!

Thanks

Andy
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Just make the getter methods const, this has changed for Irrlicht 1.4.
renegadeandy
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland
Contact:

Post by renegadeandy »

I think I have found a bug with this Camera, I have asked 2 other people incase I was being stupid but I dont think i am.

I have followed the collisionDetection tutorial example in the irrlicht folder and the code compiles - runs just fine.

Problem is, I can still quite happily float through the mesh of the terrain using the RTSCamera.

I have here the main.cpp file I am using and the RTSCamera files are simply the most up to date ones in the 1st page.

Code: Select all

#include "main.h"
#include "Buster.h"

// Irrlicht Namespaces

using namespace irr;


scene::ISceneNode* node = 0;
IrrlichtDevice* device = 0; 


int main()

{
	/////SETUP CORE DEVICE AND DRIVER SCENE MANAGER AND GUIENV AND EVENT RECEIVERS///// 
	device = createDevice(EDT_DIRECT3D8,dimension2d<s32>(512, 512),16,false,false,0);
	  
	MainEventReceiver receiver;
	
	HandleKeyEvents keyEvents;
	
	receiver.AddEventReceiver(&keyEvents);
	
	device->setEventReceiver(&receiver);
	
	device->setWindowCaption(L"Valley Attack - Irrlicht engine");
    
    IVideoDriver* driver = device->getVideoDriver();

    ISceneManager* smgr = device->getSceneManager();

    IGUIEnvironment* guienv = device->getGUIEnvironment();

    //ENDING SETUP OF CORE THINGS
    
    Buster bust(smgr,driver,"Bob",50,1,5);
    bust.hurt(5000);
  
////////SETUP HEIGHTMAP TERRAIN
   IAnimatedMesh* terrain = smgr->addTerrainMesh("Main_Ground",driver->createImageFromFile("resources/terrain-texture.jpg"),driver->createImageFromFile("heightMaps/heightmap512x512.bmp"),core::dimension2d< f32 >(20.0f, 20.0f),1000.0f,core::dimension2d< s32 >(64, 64));

   
scene::IAnimatedMeshSceneNode* terrainNode = smgr->addAnimatedMeshSceneNode(terrain); 


terrainNode->setMaterialFlag(video::EMF_LIGHTING, false);
  terrainNode->setScale(core::vector3df(10,10,10));
  terrainNode->setMaterialFlag(video::EMF_WIREFRAME, true);
  terrainNode->setMaterialTexture(1, driver->getTexture("resources/detailmap3.jpg"));
 
//DONE SETTING UP HEIGHTMAP TERRAIN


///////SETUP CAMERA AND STARTING POSITIONS
RTSCamera* camera = new RTSCamera(device,smgr->getRootSceneNode(),smgr,-1,1000.0f,10.0f,10.0f); 

camera->setTarget(vector3df(2352,2862,-1317));
camera->setROTX(91);	//setup camera to show a nice angle on things!
camera->setROTY(-330);
camera->setTranslateSpeed(50);//speed of cam
////DONE SETTING UP CAMERA STUFF


//camera->setTarget(bust.node->getPosition());
  
guienv->addStaticText(L"Hello World! This is the Irrlicht software engine running Valley Attacks first trial!",rect<int>(10,10,200,30), true, true, 0, -1);




//////////TRIAL SETTING UP collision detection bellow

scene::ITriangleSelector* selector = 0;
	
	if (terrainNode)
	{		
		//q3node->setPosition(core::vector3df(-1370,-130,-1400));

		selector = smgr->createOctTreeTriangleSelector(
           terrain->getMesh(0), terrainNode,256);
		terrainNode->setTriangleSelector(selector);
	}
	printf("\nTRIANGLE COUNT IS :%i\n",selector->getTriangleCount());
	
	 core::aabbox3d<f32> box = camera->getBoundingBox();
	   core::vector3df radius = box.MaxEdge - box.getCenter();

scene::ISceneNodeAnimator* anim =smgr->createCollisionResponseAnimator(
			selector, camera, radius,
			core::vector3df(0,0,0),
			core::vector3df(0,0,0));



			

		camera->addAnimator(anim);
		selector->drop();
		anim->drop();
	

		if(anim){
			
			printf("\nCOEM ON PLEASE DISPLAY");
		}

		
		scene::IBillboardSceneNode * bill = smgr->addBillboardSceneNode();
					bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
					bill->setMaterialTexture(0, driver->getTexture(
				         "resources/particle.bmp"));
					bill->setMaterialFlag(video::EMF_LIGHTING, false);
					bill->setSize(core::dimension2d<f32>(20.0f, 20.0f));
		
	//collision detection end
	
		
		
		
		
		scene::ISceneNode* selectedSceneNode = 0;
		scene::ISceneNode* lastSelectedSceneNode = 0;
  
		
		
		
		
		
		core::line3d<f32> line;
		core::vector3df intersection;
					core::triangle3df tri;

    while(device->run())

    { 
    	
    
int fps = driver->getFPS();
 core::stringw str =fps;
 
device->setWindowCaption(str.c_str());




driver->beginScene(true, true, SColor(255,100,101,140));

	smgr->drawAll();

	//HIGHLIGHT THE SELECTED NODE
	
	
	//test

			line.start = camera->getPosition();
			printf("\nIT THINKS CAMERA IS AT :%i",line.start.X);
			line.end = line.start +
	         ((camera->getTarget() - line.start).normalize() * 1000.0f).normalize();

			
			if (smgr->getSceneCollisionManager()->getCollisionPoint(
				line, selector, intersection, tri))
			{
				bill->setPosition(intersection);
					
				driver->setTransform(video::ETS_WORLD, core::matrix4());
				//driver->setMaterial(material);
				driver->draw3DTriangle(tri, video::SColor(0,255,0,0));
			}
	//end test
	
	
		selectedSceneNode = smgr->getSceneCollisionManager()->
	          getSceneNodeFromCameraBB(camera);

			if (lastSelectedSceneNode)
				lastSelectedSceneNode->setMaterialFlag(
	                video::EMF_LIGHTING, true);

			if (selectedSceneNode == terrainNode)
	        
				selectedSceneNode = 0;

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

			lastSelectedSceneNode = selectedSceneNode;
		//END OF HIGHLIGHTED
	
	
	
	
	guienv->drawAll();
	
	
	
	
	driver->endScene();
 
	printf("Camera x:%i, y:%i, z:%i",(int)camera->getAbsolutePosition().X,(int)camera->getAbsolutePosition().Y,(int)camera->getAbsolutePosition().Z);

	//printf("Field of view : %i",(int)camera->getROTX())  ;

	}

 

    device->drop();



    return(0);

}

I really need this one cleared up! Also the triangles are not highlighted when mouse is over them meaning something is messed up their too.

I am fairly sure the selector is created fine, reports 517811 triangles or something and the anim seems to be made fine also.

Thanks in advance,

Andy
renegadeandy
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland
Contact:

Post by renegadeandy »

Just to note - i tried with :

Code: Select all

ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
   camera->setPosition(core::vector3df(1000,1000,3000));
   camera->setTarget(terrainNode->getPosition());
   camera->setFarValue(12000);
and I cannot walk through the terrain - and it shows up the triangles.

The problem lies within the RTSCamera code - please can I get some support for this? The triangles now work, but I can stil pass directly through the terrain
renegadeandy
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland
Contact:

Post by renegadeandy »

Can somebody please fix the collision detection with this darn camera!
CmdKewin
Posts: 29
Joined: Thu Aug 17, 2006 1:49 pm

Post by CmdKewin »

Hi everyone :)

I've been away from Irrlicht Development for some time now (

Guess I could give it a shot again and fix the camera :D (finally, I would add...)
renegadeandy
Posts: 122
Joined: Sun May 25, 2008 11:14 pm
Location: Scotland
Contact:

Post by renegadeandy »

HOOORRAAAAY! MY SAVIOUR HAS COME!
xasz
Posts: 4
Joined: Thu Oct 25, 2007 2:43 pm

Post by xasz »

we working on a rts project, we used ur camera.
But i modified the camera in some ways ; some manys .
we will release an alpha soon in project announcment, i think in a week.
there u can get the source too and look what we did with ur cam.

syr for bad englisch
Post Reply