Code Search for Developers
 
 
  

kplayer.h from Spatial Knowledge Experiments at Krugle


Show kplayer.h syntax highlighted

/*
    Copyright (C) 2003, 2004, 2005 by Luca Cappa
    Written by Luca Cappa groton@users.sourceforge.net
  
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.
  
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.
  
    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef __KPLAYER__H_
#define __KPLAYER__H_

#include "movement3d.h"
#include "kquaternion.h"
#include "imesh/object.h"
#include "csgeom/box.h"
#include "igeom/objmodel.h"
#include "csgeom/objmodel.h"
#include "cstool/meshobjtmpl.h"
#include "kbasedraggable.h"
#include "kbasedraghandler.h"

class KWireframe;
class csMeshObject;

SCF_VERSION (KPlayer, 0, 0, 1);

class KPlayer : public csObject
{
private:

  /*
    Some useful constants.
  */
  static const float GROUND_Y;
  static const float BODY_HEIGHT;
  static const float LEGS_HEIGHT;

  csRef<KSprite3D> m_arrow;

#ifndef __USE_CAL3D__
  csRef<KSprite3D> m_head;
  csRef<KSprite3D> m_top;
  csRef<KSprite3D> m_bottom;

  //Player's colliders.
  csRef<KSprite3D> m_bodyCollMesh;
  csRef<csColliderWrapper> m_bodyCollider;
  csRef<KWireframe> m_bodyCollTracker;
  csRef<KSprite3D> m_feetsCollMesh;
  csRef<csColliderWrapper> m_feetsCollider;
  csRef<KWireframe> m_feetsCollTracker;
#else // __USE_CAL3D__
  csRef<iMeshWrapper> m_meshW;
  csRef<csColliderWrapper> m_collider;
  csRef<KWireframe> m_playerCollTracker;
  csRef<KSprite3D> m_playerCollMesh;
#endif // __USE_CAL3D__

  //Angles.
  KQuaternion m_headQ;
  KQuaternion m_bodyQ;
  
  //Position of the feets! i.e. the eyes are at position 
  //m_mov->GetPosition ().y + m_height
  csVector3 m_oldPos;
  iSector* m_sector;
  
  /*
    The height of the eyes.
  */
  float m_height;
  
  /*
    Actions state.
  */
  bool m_walking;
  bool m_showArrow;
  bool m_showHead;

  /*
    Dragging
  */
  csVector3 m_hitPoint;
  DRAG_TYPE m_dragType;
public:

  csVector3 m_headOffset;// (0.0f, -0.27f, 0.03f)
  csVector3 m_topOffset;// (-0.09f, 0.0f, 0.11f)
  csVector3 m_bottomOffset;// (-0.02f, 0.13f, 0.25f)

  csVector3 m_bodyRadius;
  csVector3 m_feetsRadius;

  csVector3 m_playerAcc;//??
  float m_friction;
  float m_accK;
  float m_FOVAngle;
  int m_FOVWidth;
  Movement3D m_mov3d;

  /*
  ctor
  */
  KPlayer ();
  
  /*
  dtor
  */
  virtual ~KPlayer ();

  void LoadPlayerMeshes ();

  bool Initialize ();

  void CalculatePlayerAcceleration (bool p_transBody, bool p_rotBody,
    float speedRadians);

  void SetPosition (csVector3 p_pos);
  csVector3 GetPosition ();

  void SetHeight (float p_height);
  float GetHeight ();

  void Hiding (bool p_hiding);

  void SetWalking (bool);
  void ShowArrow (bool);
  void ShowHead (bool);
  
  void SetBodyAngle (KQuaternion const&);
  KQuaternion const&  GetBodyAngle ();
  
  void SetHeadAngles (KQuaternion const&);
  KQuaternion const& GetHeadAngles ();

  void GetHeadAngles (csVector3& l_angles);
  void SetHeadAngles (csVector3& l_angles);

  csColliderWrapper* GetBodyColliderWrapper ();
  csColliderWrapper* GetFeetsColliderWrapper ();
  csVector3 GetNextWalkingStep (float p_seconds);
  void Walk (float p_seconds);

  const csRefArray<iMeshWrapper> GetMeshWrappers () const;

  void SetupFrame ();

  //
  //Methods for iDragHandler interface.
  bool Drag (float p_x, float p_y, const csVector3&, DRAG_TYPE p_dT);
  bool Undrag (float p_x, float p_y);
  bool HandlerDrag (float, float);

  SCF_DECLARE_IBASE_EXT (csObject);

  struct eiKDragHandler : public KBaseDragHandler
  {
    SCF_DECLARE_EMBEDDED_IBASE (KPlayer);

    bool Drag (float p_x, float p_y, const csVector3& p_v, DRAG_TYPE p_dT)
    {
      return scfParent->Drag (p_x, p_y, p_v, p_dT);
    }

    bool HandleDrag (float p_x, float p_y)
    {
      return scfParent->HandlerDrag (p_x, p_y);
    }

    
  } scfiKDragHandler;

  struct eiKDraggable : public KBaseDraggable
  {
    SCF_DECLARE_EMBEDDED_IBASE (KPlayer);
    
    const csRefArray<iMeshWrapper> GetMeshWrappers () const
    {
      return scfParent->GetMeshWrappers ();
    }
  } scfiKDraggable;

  
  friend struct eiKDragHandler;
};

#endif //__KPLAYER__H_




See more files for this project here

Spatial Knowledge Experiments

A simulation of 3D virtual worlds for psychological experiments

Project homepage: http://sourceforge.net/projects/ske
Programming language(s): C,C++,Perl
License: other

  isense/
  joystick/
  Jamfile
  KImageCardinalDirection.h
  SKE.cpp
  SKE.h
  eulerangles.c
  eulerangles.h
  ikdraggable.cpp
  ikdraggable.h
  ikdraghandler.h
  ikmission.h
  ikxmlreader.h
  ikxmlwriter.h
  kappstate.cpp
  kappstate.h
  kbasedraggable.cpp
  kbasedraggable.h
  kbasedraghandler.cpp
  kbasedraghandler.h
  kblock.cpp
  kblock.h
  kblockId.h
  kblockid.cpp
  kcamera.cpp
  kcamera.h
  kcollision.cpp
  kcommandprocessor.cpp
  kcommandprocessor.h
  kconstant.cpp
  kconstant.h
  kcursor3d.cpp
  kcursor3d.h
  kdata.cpp
  kdata.h
  kdatalist.cpp
  kdatalist.h
  kdragmanager.cpp
  kdragmanager.h
  keventhandlermanager.cpp
  keventhandlermanager.h
  kflags.cpp
  kflags.h
  kimagecardinaldirection.cpp
  kkeys.cpp
  kkeys.h
  kkeystate.cpp
  kkeystate.h
  klandmark.cpp
  klandmark.h
  klandmarklist.cpp
  klandmarklist.h
  klight.cpp
  klight.h
  klightlist.cpp
  klightlist.h
  kmap.cpp
  kmap.h
  kmission.cpp
  kmission.h
  kmissiontype.cpp
  kmissiontype.h
  kmode.cpp
  kmode.h
  kmousemanager.cpp
  kmousemanager.h
  kobject3d.cpp
  kobject3d.h
  korientation.cpp
  korientation.h
  kpath.cpp
  kpath.h
  kpathfollower.cpp
  kpathfollower.h
  kplayer.cpp
  kplayer.h
  kposition.cpp
  kposition.h
  kquaternion.cpp
  kquaternion.h
  ksaveddatamanager.cpp
  ksaveddatamanager.h
  ksegment3.h
  ksign.cpp
  ksign.h
  ksprite3d.cpp
  ksprite3d.h
  ksprite3dlist.cpp
  ksprite3dlist.h
  kterrain.cpp
  kterrain.h
  kthing.cpp
  kthing.h
  kutil.cpp
  kutil.h
  kwireframe.cpp
  kwireframe.h
  kxmlhelper.h
  movement1d.h
  movement3d.h
  quattypes.h