Show kpath.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 __KPATH_H__
#define __KPATH_H__
SCF_VERSION (KPath, 0, 0, 2);
#include "imesh/object.h"
#include "csgeom/box.h"
#include "csgeom/objmodel.h"
#include "igeom/objmodel.h"
#include "cstool/meshobjtmpl.h"
#include "cstool/rendermeshholder.h"
#include "ivideo/rendermesh.h"
struct iEngine;
struct iKXMLReader;
struct iKXMLWriter;
struct iEngine;
struct iMeshWrapper;
class csVector;
class csPath;
class csMeshObject;
class KPath : public csMeshObject, public iKXMLReader, public iKXMLWriter
{
private:
iMaterialWrapper* mMaterial;
/**
* Indicates if the path has an inverted versus.
*/
bool mInverted;
/**
* The render mesh holder is used by GetRenderMeshes() to supply
* render meshes that can be returned by that function.
*/
csRenderMeshHolder m_rMHolder;
/**
* The standard render buffer holder. It takes care of giving
* the renderer all required renderbuffers.
*/
csRef<csRenderBufferHolder> m_bufferHolder;
/**
* The string name of the O2W transformation.
*/
csStringID mString_object2world;
/**
* Pretty useless. //??
*/
iBase* m_logparent;
/**
* Buffers for the renderers.
*/
csRef<iRenderBuffer> m_vertexBuffer;
csRef<iRenderBuffer> m_indexBuffer;
/**
* Is this path object invisible?
*/
bool m_invisible;
/**
* Are the path's balls invisible?
*/
bool m_ballsInvisible;
/**
* Has the mesh been prepared to be drawn?
*/
bool m_preparedForDrawing;
protected:
csRef<iMeshWrapper> m_mW;//Contains the meshWrapper for this iMeshObject.
csRefArray<iMeshWrapper> m_balls;//contains all the obj meshes.
/**
* Name.
*/
csRef<iString> mName;
char* mLineDefaultMaterialName;
csRef<iEngine> m_engine;
csRef<iLoader> m_loader;
csRef<iGraphics3D> m_g3d;
csPath* m_path;
/**
* Contains last linear velocity passed as argument to Update();
*/
float m_velocity;
//Datas for PostDrawLine
csVector3 m_start;
csVector3 m_end;
public:
KPath ();
virtual ~KPath ();
void Clear ();
bool SetInvisible(bool p_invisible);
bool SetBallInvisible (bool p_ballsInvisible);
void SetDefaultMaterialForLineDrawing (char const* pName);
bool LoadDefaultMaterialForLineDrawing (iMaterialWrapper*& pMaterial);
void SetInverted (bool pInverted);
bool GetInverted ();
//
//iKXMLWriter/Reader interfaces.
bool Write (iDocumentNode* p_parent) const;
bool Read (iDocumentNode* p_parent);
void AddPoint (float p_x, float p_z);
void GetPoints (csDirtyAccessArray<csVector3>& p_points);
void GetSmoothedPointsAndNormals (csDirtyAccessArray<csVector3>& p_points,
csDirtyAccessArray<csVector3>& p_normals);
void Init (float p_velocity);
void GetPositionAtTime (csVector3*const, csVector3*const, csVector3*const,
float p_time);
float GetDurationTime (float p_velocity);
float GetMeters ();
bool IsEmpty ();
void DrawLine (iRenderView* p_rView, csVector3& p_1,
csVector3& p_2, int p_color);
void GetObjectBoundingBox (csBox3& bbox)
{
bbox.Set (-100000, -100000, -100000, 100000, 100000, 100000);
return;
}
void GetRadius (csVector3& rad, csVector3& cent)
{
rad.Set (200000, 200000, 200000);
cent.Set (0,0,0);
}
SCF_DECLARE_IBASE;
virtual iMeshObjectFactory* GetFactory () const { return NULL; }
virtual void UpdateLighting (iLight**, int, iMovable*) { }
virtual void SetVisibleCallback (iMeshObjectDrawCallback*) { }
virtual iMeshObjectDrawCallback* GetVisibleCallback () const { return NULL; }
virtual void NextFrame (csTicks, const csVector3& /*pos*/) { }
virtual bool WantToDie () const { return false; }
virtual void HardTransform (const csReversibleTransform&) { }
virtual bool SupportsHardTransform () const { return false; }
virtual bool HitBeamOutline (const csVector3&, const csVector3&,
csVector3&, float*)
{ return false; }
virtual bool HitBeamObject (const csVector3&, const csVector3&,
csVector3&, float*) { return false; }
virtual void SetLogicalParent (iBase* p_lP)
{
m_logparent = p_lP;
}
virtual iBase* GetLogicalParent () const
{
return m_logparent;
}
//------------------------- iObjectModel implementation ----------------
class ObjectModel : public csObjectModel
{
SCF_DECLARE_EMBEDDED_IBASE (KPath);
virtual long GetShapeNumber () const { return 1; }
virtual iPolygonMesh* GetPolygonMeshColldet () { return NULL; }
virtual iPolygonMesh* GetPolygonMeshViscull () { return NULL; }
virtual csPtr<iPolygonMesh> CreateLowerDetailPolygonMesh (float)
{ return NULL; }
virtual iPolygonMesh* GetPolygonMeshBase () { return NULL; }
virtual void SetPolygonMeshColldet (iPolygonMesh*) { }
virtual void SetPolygonMeshViscull (iPolygonMesh*) { }
virtual void GetObjectBoundingBox (csBox3& bbox)
{
scfParent->GetObjectBoundingBox (bbox);
}
virtual void SetObjectBoundingBox (csBox3 const& bbox)
{
scfParent->SetObjectBoundingBox (bbox);
}
virtual void GetRadius (csVector3& rad, csVector3& cent)
{
scfParent->GetRadius (rad, cent);
}
virtual void AddListener (iObjectModelListener*)
{
}
virtual void RemoveListener (iObjectModelListener*)
{
}
} scfiObjectModel;
friend class ObjectModel;
void PreGetBuffer (csRenderBufferHolder* p_holder, csRenderBufferName p_buffer);
csRenderMesh** KPath::GetRenderMeshes (int& p_count, iRenderView* p_rView,
iMovable* p_movable, uint32 p_frustumMask);
virtual iObjectModel* GetObjectModel () { return &scfiObjectModel; }
virtual bool SetColor (const csColor&) { return false; }
virtual bool GetColor (csColor&) const { return false; }
virtual bool SetMaterialWrapper (iMaterialWrapper*) { return false; }
virtual iMaterialWrapper* GetMaterialWrapper () const { return NULL; }
/**
* Get the name of this object. it will never return a 0 pointer.
*/
const char* GetName () const
{
return mName->GetData ();
}
/**
* Set the name of this object. If the name is 0, the name is set to an empy string
* i.e. "" .
* @param p_name The name of this object.
*/
void SetName (const char* p_name)
{
mName.AttachNew (new scfString (p_name ? p_name : ""));
}
};//class
#endif // __KPATH_H__
See more files for this project here