ICameraSceneNodeFS: a flightsim camera

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

ICameraSceneNodeFS: a flightsim camera

Post by dudMaN »

This probably isnt the best flightsim camera ever made, but last time i checked it works :P

theres no movement functions, i'll probably just make it inheret from the FPS camera and
then remove the FPSness from it ;)

anyway here it is


#define SCREENW and #define SCREENH..

Code: Select all

class ICameraSceneNodeFS : public ICameraSceneNode {
 protected:
  position2d<s32> mousePos, zero;
  IAnimatedMeshSceneNode *plane;
 public:
  ICameraSceneNodeFS(IAnimatedMeshSceneNode *p) {
   plane = p;
   mousePos = position2d<s32>((s32)0,(s32)0);
   zero = position2d<s32>((s32)(SCREENW/2),(s32)(SCREENH/2));
  }
  void update(IrrlichtDevice *dv) {
   mousePos = dv->getCursorControl()->getPosition();
   if(mousePos.X > zero.X) { // moved to the right
    // move camera
    vector3df p = getRotation();
    p.Y += 1;
    setRotation(p);

    // tilt plane
    vector3df z = plane->getRotation();
    z.Z += 1;
    plane->setRotation(z);
   } 

   if(mousePos.X < zero.X) { // moved to the left
    // move camera
    vector3df p = getRotation();
    p.Y -= 1;
    setRotation(p);

    // tilt plane
    vector3df z =plane-> getRotation();
    z.Z -= 1;
    plane->setRotation(z);
   } 

   if(mousePos.Y > zero.Y) { // moved down
    vector3df p = getRotation();
    p.X += 1;
    setRotation(p);
   } 

   if(mousePos.Y < zero.Y) { // moved up
    vector3df p = getRotation();
    p.X -= 1;
    setRotation(p);
   }
   dv->getCursorControl()->setPosition(position2d<s32>((SCREENW/2),(SCREENH/2)));
 }
};
EDIT: Fixed device mess and a couple other things, also added a plane mesh.

i just threw it together from boredome.. hope it'll be of some use to someone!

-dudMaN

EDIT: hey, vitek,
i just threw it together from boredome.. hope it'll be of some use to someone!
[/quote]
Last edited by dudMaN on Fri May 25, 2007 7:43 pm, edited 6 times in total.
monkeycracks
Posts: 1029
Joined: Thu Apr 06, 2006 12:45 am
Location: Tennesee, USA
Contact:

Post by monkeycracks »

Moving forward?
:P
Looks good minus that.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Uhh, I'm assuming that is supposed to be C++...
  1. the rotate speed is frame rate dependent.
  2. it will misbehave once the mouse gets to the edge of the screen.
  3. it doesn't implement the ICameraSceneNode interface, so there is no chance the user can't instantiate one.
  4. you can't create an IrrlichtDevice by value, you have to use pointers or references because it is an abstract interface.
dudMaN
Posts: 111
Joined: Fri Mar 02, 2007 6:37 pm

Post by dudMaN »

1. who cares?
2. ok, i'll make the mouse zap back to the center after being tested
3. uh.. yes it does :)
4. fixed
Ico
Posts: 289
Joined: Tue Aug 22, 2006 11:35 pm

Post by Ico »

Frame rate dependency: Go, download "nibbles.bas" and play a round. :)
Dances
Posts: 454
Joined: Sat Jul 02, 2005 1:45 am
Location: Canada
Contact:

Post by Dances »

People care about 1. because if you have a network game and one computer is faster than the other then the faster one will be able to rotate his plane faster; which is not fair.

Also if someone is using a slow computer their plane will rotate horrifically slow so he wont fly very well.

Base the rotation on time.

I believe that dv->getCursorControl()->setPosition(position2d<s32>(0,0)
is the top left of the screen; this would prevent you from moving the mouse left or up (at least the last time I worked with the mouse it did); center it instead.

Also, you don't need a variable for the last position of the mouse if you reset the position every time.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Uhh. It most definitely does not implement the ICameraSceneNode interface. If you had done this, you would need to declare and define each of the following abstract functions in your derived camera class.

Code: Select all

// these are straight out of ICameraSceneNode.h.
// all derived camera classes must implement them, or inherit from a class that does.

virtual void setProjectionMatrix(const core::matrix4& projection) = 0;
virtual const core::matrix4& getProjectionMatrix() = 0;
virtual const core::matrix4& getViewMatrix() = 0;
virtual bool OnEvent(SEvent event) = 0;
virtual void setTarget(const core::vector3df& pos) = 0;
virtual core::vector3df getTarget() const = 0;
virtual void setUpVector(const core::vector3df& pos) = 0;
virtual core::vector3df getUpVector() const = 0;
virtual f32 getNearValue() = 0;
virtual f32 getFarValue() = 0;
virtual f32 getAspectRatio() = 0;
virtual f32 getFOV() = 0;
virtual void setNearValue(f32 zn) = 0;
virtual void setFarValue(f32 zf) = 0;
virtual void setAspectRatio(f32 aspect) = 0;
virtual void setFOV(f32 fovy) = 0;
virtual const SViewFrustum* getViewFrustum() const = 0;
virtual void setInputReceiverEnabled(bool enabled) = 0;
virtual bool isInputReceiverEnabled() = 0;
Also, some more stuff that I've noticed since my last stop here...
  1. the constructor of your camera class must call the base class constructor, providing the required arguments.
  2. the variable p is not defined outside the constructor of your class. you've made a copy of p and named it plane.
just threw it together from boredome.. hope it'll be of some use to someone!
If your code won't compile, and even if it did, it won't be useful to anyone. Sorry I'm being a bit harsh, but lots of newbies turn here for code that they can use. They stumble onto a landmine like this and then spend days trying to figure out why they can't get it to work.

It is not like I've never submitted bad code to the forums before either. But if I do submit something that doesn't work, I will fix and resubmit so that others can benefit from that work.

Travis
Post Reply