Can I create a not-FPS 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.
Peppe
Posts: 16
Joined: Wed Aug 08, 2007 5:12 pm

Can I create a not-FPS camera?

Post by Peppe »

Hi to all! :D I want to create a camera not-fps, but I don't know the procedures. Can you explain to me the procedures?

thank you very much!

PS: excuse me if I committed several mistakes, but I'm Italian and I know only little bit of English. :oops:
randomMesh
Posts: 1186
Joined: Fri Dec 29, 2006 12:04 am

Post by randomMesh »

Have a looke here.

Code: Select all

irr::scene::ICameraSceneNode* camera = smgr->addCameraSceneNode();
And then you are able to set the parent, position, target to look at, etc. like this:

Code: Select all

camera->setParent(parentNode);
camera->setPosition(irr::core::vector3df(0.0f, 0.0f, 0.0f));
camera->setTarget(irr::core::vector3df(0.0f, 0.0f, 0.0f));
The API dokumentation is your friend.
Peppe
Posts: 16
Joined: Wed Aug 08, 2007 5:12 pm

Post by Peppe »

Thank you, randomMesh, but my real problem is the input.. :oops:

I partially solved the problem, for the camera movement foward/Backward, Left/Right:

Code: Select all

class MyEventReceiver : public IEventReceiver
{
 
	 
 

	virtual bool OnEvent(SEvent event)
	{
		 
		if (event.EventType == irr::EET_KEY_INPUT_EVENT&& event.KeyInput.PressedDown)
		{
			 if(event.KeyInput.Key== KEY_ESCAPE)
              {
              
 device->closeDevice(); 
 return true;
    }
       if(event.KeyInput.Key== KEY_UP )
              {  
                    Spostamento_CameraX=Spostamento_CameraX+5;           
                                return true;
    }
      
             if(event.KeyInput.Key== KEY_DOWN )
              {  
                    Spostamento_CameraX=Spostamento_CameraX-5;           
                                return true;
    }
      
       if(event.KeyInput.Key== KEY_RIGHT )
              {  
                    Spostamento_CameraZ=Spostamento_CameraZ-5;           
                                return true;
    }	
        if(event.KeyInput.Key== KEY_LEFT )
              {  
                    Spostamento_CameraZ=Spostamento_CameraZ+5;           
                                return true;
    }	

//next ->  
But now i have a problem whit mouse control fot the target movement:

Code: Select all


//<-previus
if (event.EventType==irr::EET_MOUSE_INPUT_EVENT){
    if(event.MouseInput.Event==EMIE_MOUSE_MOVED&&event.MouseInput.Event==EMIE_RMOUSE_PRESSED_DOWN)                                           
  {
  if(device->getCursorControl()->getPosition().X>512){                                            
    CameraTarX=CameraTarX-3;
    return true;
    }                                           
    }                                           
   }                                            
  }                                             
  }
	private:
	scene::ISceneNode* Terrain;	
	};
I pressed the Right Mouse Button, but I can't move the target :cry:

can you help me?
Peppe
Posts: 16
Joined: Wed Aug 08, 2007 5:12 pm

Post by Peppe »

can you help me?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

One event cannot be of two types. You have to remember the state of the mouse buttons and reset it when the button_up event arrives.
Peppe
Posts: 16
Joined: Wed Aug 08, 2007 5:12 pm

Post by Peppe »

Ok, I solved...but I have another problem:

I move the target, but the target stop at 90 degrees and at -90 degrees. :shock: .

the maximum rotation of the target, in my program is 180 degrees :shock: ... I post my code:

Code: Select all

camera->setPosition(core::vector3df( Spostamento_CameraX*2,255*2,Spostamento_CameraZ*2));
  if (sganctarg==true){
  
  rotazione_iniziale = camera->getTarget() ;
   point = device->getCursorControl()->getPosition(); 
   if (point.X  >= 645){ 
  
    rotazione_iniziale.X=rotazione_iniziale.X-50;
 
   }
   if (point.X <= 635){ 
   
    rotazione_iniziale.X=rotazione_iniziale.X+50;
   }
      if (point.Y  >= 390){ 
   rotazione_iniziale.Y=rotazione_iniziale.Y-50;
   
   }
   if (point.Y <= 410){ 
   rotazione_iniziale.Y=rotazione_iniziale.Y+50;
   }
   camera->setTarget(rotazione_iniziale);
I want my camera rotation is = 360 degrees and not 180 degrees. :cry:

Can you help me? :cry:
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

No, you don't have 180°, its lesser !!! ;)
The problem is you're looking just at one axis, you'll have to look in a circle around you...
look at this pic, it should show you what's wrong with your code:
Image
(same for the Y-axis)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Peppe
Posts: 16
Joined: Wed Aug 08, 2007 5:12 pm

Post by Peppe »

Uhm...I understand... :D

I calculate the Z position by the Pythagoras' theorem :

the radius of circle is the hypotenuse and the x value is a triangle's leg.

the z value is another triangle's leg.

Value.Z = sqrt(radius*radius - Value.X*Value.X) .

but how I have the radius value??

thank you very much. :wink:
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Well, Pythagoras is the wrong guy for this :lol:
you should use an view angle and then triangulate X and Z...
you should do something like this:

Code: Select all

   if (point.X  >= 645){
     rotAngle -= 1; // rotate 1° anti clockwise, but should it not be clockwise?
     if(rotAngle < 0) rotAngle += 360;
   }
   if (point.X <= 635){
     rotAngle += 1; // rotate 1° clockwise, but should it not be anti clockwise?
     if(rotAngle >= 360) rotAngle -= 360;
   }
then you should define a view distance that always is the same, this can be any value so we simply can take 1
Image
now you can easily calculate X and Z:
sin(alpha) = X / 1 >>> X = sin(alpha) * 1 >>> X = sin(rotAngle)
cos(alpha) = Z / 1 >>> Z = cos(alpha) * 1 >>> Z = cos(rotAngle)

well, I hope I made no mistakes as I wrote this out of the top of my head and I'm tired... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Peppe
Posts: 16
Joined: Wed Aug 08, 2007 5:12 pm

Post by Peppe »

ok, the debug values reading the movement, but the camera don't move :shock:
Peppe
Posts: 16
Joined: Wed Aug 08, 2007 5:12 pm

Post by Peppe »

If I moltiplicate the cosinus and the sinus for a high value (eg: 880) I generate a "earthquake" :shock: :shock: :shock: :shock:

hum...like a two forces stop the camera:

Anti-camera movement <----MyCamera----> camera movement
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

Well, I don't know what you're exactly doing there... ;)
but you don't need to multiply cos and sin with any other value than 1, but you have to add your camera position...
for the earthquake it could be that you'll have to update the absolute camera position afterwards:

Code: Select all

vector3df target = cam->getPosition();
target.X += sin(rotAngle);
target.Z += cos(rotAngle);
camera->setTarget(target);
camera->updateAbsolutePosition();
this should work for left/right view, for up/down it's similar...
Maybe sin and cos needs radians instead of degrees (the code I wrote is more a pseudo code)...
Last edited by Acki on Mon Aug 20, 2007 9:40 pm, edited 1 time in total.
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Peppe
Posts: 16
Joined: Wed Aug 08, 2007 5:12 pm

Post by Peppe »

Dont work :(

this is my loop:

Code: Select all

camera->setPosition(core::vector3df( Spostamento_CameraX*2,255*2,Spostamento_CameraZ*2));
  
  if (sganctarg==true){
  //I use the boolean SgancTarg for the right mouse button is pressed.

  
   point = device->getCursorControl()->getPosition(); 
   if (point.X  >= 645){ 
   Rotangle  = Rotangle - 1;
   if(Rotangle < 0) Rotangle  =Rotangle + 360;
   
    }
   if (point.X <= 635){ 
   
      Rotangle  = Rotangle +1;
   if(Rotangle >= 0) Rotangle  = Rotangle -360;
    
 
   }
      if (point.Y  >= 390){ 
   rotazione_iniziale.Y=rotazione_iniziale.Y-50; 
   
   }
   if (point.Y <= 410){ 
   rotazione_iniziale.Y=rotazione_iniziale.Y+50;
   }

//"rotazione_iniziale" is the target movement.
   rotazione_iniziale.X =Spostamento_CameraX + sin(Rotangle)  ;
   rotazione_iniziale.Z =Spostamento_CameraZ + cos(Rotangle)   ;
  
   camera->setTarget(rotazione_iniziale);
  camera->updateAbsolutePosition();
    
}
   
 
   
			
        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;
			// Also print terrain height of current camera position
			// We can use camera position because terrain is located at coordinate origin
			str += " rot: ";
			 
            str += Rotangle;
       
			device->setWindowCaption(str.c_str());
			lastFPS = fps;
		}
		
	}
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

ohh, your fast (or I'm to tired) !!! :lol:
well, one error in the code:

Code: Select all

 if (point.X <= 635){
      Rotangle  = Rotangle +1;
   if(Rotangle >= 0) Rotangle  = Rotangle -360;
   } 
must be:

Code: Select all

 if (point.X <= 635){
      Rotangle  = Rotangle +1;
   if(Rotangle >= 360) Rotangle  = Rotangle -360;
   } 
and if I rember right you'll have to use radians, so you'll have to multibly the angle with pi/180:

Code: Select all

rotazione_iniziale.X =Spostamento_CameraX + sin(Rotangle * 3.14156 / 180.0);
   rotazione_iniziale.Z =Spostamento_CameraZ + cos(Rotangle * 3.14156 / 180.0);
and don't forget to use a float type for the Rotangle var...

as I mentioned, all this I'm doing just out of my head... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Peppe
Posts: 16
Joined: Wed Aug 08, 2007 5:12 pm

Post by Peppe »

uhm..I have a strange effect:

If I click right mouse button, My target is (0,0,0), but if I move the camera with directional keys , I rotate the camera :shock: .

Hem...can I rotate the camera whit the mouse?
Post Reply