About Store Forum Documentation Contact



Post Reply 
Positioning camera at marker
Author Message
monotonic Offline
Member

Post: #1
Positioning camera at marker
Hi All,

I've just started playing around with the engine and have created a marker object+class in the editor and positioned them in the world. Then in my world loader class I'm trying to position the camera where one of these markers is positioned. My camera is positioned within the world but it is always at the origin of the world, I'm scratching my head as to what the problem could be.

Below is the snippet of code that finds the player start marker from the object map and then positions the camera:

Code:
REPA(PlayerStartMarkers)
   {
      if( PlayerStartMarkers[i].PlayerCharacter) {
         Cam.dist =10;
         Cam.yaw  =-PI_4;
         Cam.pitch=-0.5;
         Vec Pos = PlayerStartMarkers[i].pos();
         Cam.at.set(Pos.x, Pos.y, Pos.z);
      }
   }

And this is my simple PlayerStartMarker class:

Code:
class PlayerStart : public Game.Obj
{
  
protected:
  
   // members
   Matrix m_Matrix;
  
  
public:
  
   // properties
   bool PlayerCharacter;
  
  
public:
  
   // ctor / dtor
   PlayerStart();
   ~PlayerStart();
  
  
public:
  
   // methods
   virtual void create( Game.ObjParams& obj );
   virtual Vec pos( );
   virtual void pos( C Vec &pos );
   virtual Matrix matrix( );
   virtual void matrix( C Matrix &matrix );
   virtual UInt drawPrepare();
   virtual bool update();
  
}



// constructor
PlayerStart::PlayerStart()
{
  
}

// destructor
PlayerStart::~PlayerStart()
{
  
}

// handles reading the parameters
void PlayerStart::create(Game.ObjParams& obj)
{
   //super.create(obj);
   if( Param * p = obj.findParam("Player Character")) PlayerCharacter = p.asBool();
}

Vec PlayerStart::pos( )
{
   return m_Matrix.pos;
}
void PlayerStart::pos( C Vec &pos )
{
   m_Matrix.pos = pos;
}
Matrix PlayerStart::matrix( )
{
   return m_Matrix;
}
void PlayerStart::matrix( C Matrix &matrix )
{
   m_Matrix = matrix;
}
UInt PlayerStart::drawPrepare()
{
   return IndexToFlag(RM_SOLID);
}
bool PlayerStart::update()
{
   return true;
}
FYI - This class is only meant to be visible within the editor and not rendered within the world at runtime. Do I need to multiply the Pos vector by the world matrix?

My C++ is very rusty, I haven't used it for many years so forgive any ugliness.

Any help would be greatly appreciated.
(This post was last modified: 08-30-2014 07:15 AM by monotonic.)
08-29-2014 11:15 PM
Find all posts by this user Quote this message in a reply
monotonic Offline
Member

Post: #2
RE: Positioning camera at marker
Update: After debugging through the code I can see that the position vector that I'm getting back from the marker is (0.0013f, 0.0013f, 0.0013f), which is odd because the marker is positioned right at the edge of the terrain roughly (128.0f, 0.0f, 128.0f)
08-30-2014 08:32 AM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #3
RE: Positioning camera at marker
You have "super.create(obj)" marked as comment, you should change that.
08-30-2014 08:57 AM
Find all posts by this user Quote this message in a reply
monotonic Offline
Member

Post: #4
RE: Positioning camera at marker
(08-30-2014 08:57 AM)Pherael Wrote:  You have "super.create(obj)" marked as comment, you should change that.

Hi Pherael,

The base class Game.Obj has a pure virtual function for the create function so calling it would result in an error. This is still there because I copy and pasted some code from another class.
08-30-2014 11:20 AM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #5
RE: Positioning camera at marker
Ah, yes. I was thinking your class inherit from Game.Static instead Game.Obj because I often do that. If you do that everythink should work.

The secon options is manually set data from ObjParams. Add something like this in create function: m_Matrix = obj.matrix; or m_Matrix.pos=obj.matrix.pos
08-30-2014 12:09 PM
Find all posts by this user Quote this message in a reply
Rubeus Offline
Member

Post: #6
RE: Positioning camera at marker
Also, the Cam code is a litte goofy- setting those variables won't actually do anything. The best options are:
1) Modify Cam.matrix directly, then use Cam.set()
2) Use one of the built in functions like Cam.setAngle(C Vec &pos, Flt yaw, Flt pitch, Flt roll).set()

The Cam.yaw, pitch, roll, dist, etc don't actually do anything. They are there so you can see what the values are when using the Cam.setX functions, which assign them within the function.
Using Cam.set copies Cam.matrix to the actual camera matrix.

I've been building a camera library, so I've become rather familiar with the camera system.
08-30-2014 01:54 PM
Find all posts by this user Quote this message in a reply
monotonic Offline
Member

Post: #7
RE: Positioning camera at marker
Hi Pherael / Rubeus,

Adding m_Matrix = obj.matrix into the world loader code and using Cam.setPosDir(Pos, Vec(0, 0, 0), Vec(0, 1, 0)).set(); to position the camera fixed the problem.

Thank you very much for your help it is very much appreciated.
08-31-2014 07:39 AM
Find all posts by this user Quote this message in a reply
Post Reply