Show kposition.cpp syntax highlighted
/*
Copyright (C) 2003, 2004 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.
*/
#include "cssysdef.h"
#include "csutil/sysfunc.h"
#include "csutil/cscolor.h"
#include "csutil/cmdhelp.h"
#include "csutil/cspmeter.h"
#include "csutil/csstring.h"
#include "csutil/scfstr.h"
#include "csutil/xmltiny.h"
#include "csutil/array.h"
#include "cstool/csview.h"
#include "cstool/initapp.h"
#include "cstool/collider.h"
#include "iutil/vfs.h"
#include "iutil/eventq.h"
#include "iutil/event.h"
#include "iutil/objreg.h"
#include "iutil/csinput.h"
#include "iutil/virtclk.h"
#include "iutil/plugin.h"
#include "iutil/string.h"
#include "iengine/sector.h"
#include "iengine/engine.h"
#include "iengine/camera.h"
#include "iengine/light.h"
#include "iengine/texture.h"
#include "iengine/mesh.h"
#include "iengine/movable.h"
#include "iengine/material.h"
#include "imesh/thing.h"
#include "imesh/object.h"
#include "imesh/sprite3d.h"
#include "ivideo/graph3d.h"
#include "ivideo/graph2d.h"
#include "ivideo/natwin.h"
#include "ivideo/txtmgr.h"
#include "ivideo/texture.h"
#include "ivideo/material.h"
#include "ivideo/fontserv.h"
#include "igraphic/imageio.h"
#include "imap/loader.h"
#include "ivaria/reporter.h"
#include "ivaria/stdrep.h"
#include "ivaria/conout.h"
#include "ivaria/reporter.h"
#include "ivaria/stdrep.h"
#include "ivaria/collider.h"
#include "csgeom/quaterni.h"
#include "csgeom/transfrm.h"
#include "csgeom/math3d_d.h"
#include "csgeom/math3d.h"
#include "igeom/polymesh.h"
#include "igeom/objmodel.h"
#include "imap/loader.h"
#include "iaws/aws.h"
#include "iaws/awscnvs.h"
#include "korientation.h"
#include "kblock.h"
#include "kmap.h"
#include "kblockid.h"
#include "kflags.h"
#include "kappstate.h"
#include "ske.h"
#include "ksprite3d.h"
#include "kdata.h"
//Include file for this file.
#include "kposition.h"
SCF_IMPLEMENT_IBASE (KPosition)
SCF_IMPLEMENTS_INTERFACE (iKXMLWriter)
SCF_IMPLEMENTS_INTERFACE (iKXMLReader)
SCF_IMPLEMENT_IBASE_END
KPosition::KPosition ()
{
SCF_CONSTRUCT_IBASE (NULL);
*this = KPosition ("no_name");
}
KPosition::KPosition (const char* p_name)
{
SCF_CONSTRUCT_IBASE (NULL);
if (p_name != NULL)
m_name.AttachNew (new scfString (p_name));
else
m_name.AttachNew (new scfString ("null_name"));
m_bodyQ.SetWithEuler (csVector3 (0,0,0));
}
KPosition::~KPosition()
{
SCF_DESTRUCT_IBASE ();
}
void KPosition::SetName (const char* p_name)
{
m_name.AttachNew (new scfString (p_name));
}
char* KPosition::GetName ()
{
return m_name->GetData ();
}
void KPosition::SetBodyAngle (KQuaternion const& p_q)
{
m_bodyQ = p_q;
}
KQuaternion const& KPosition::GetBodyAngle ()
{
return m_bodyQ;//??UGLY!
}
const csVector3& KPosition::GetPosition () const
{
return m_position;
}
void KPosition::SetPosition (const csVector3& p_vec)
{
m_position = p_vec;
}
bool KPosition::Write (iDocumentNode* p_parent) const
{
csRef<iDocumentNode> l_initPosNode =
p_parent->CreateNodeBefore (CS_NODE_ELEMENT, NULL);
l_initPosNode->SetValue ("init_position");
if (m_name->GetData () == 0)
l_initPosNode->SetAttribute ("name", "no-name");
else
l_initPosNode->SetAttribute ("name", m_name->GetData ());
l_initPosNode->SetAttributeAsFloat ("x", m_position.x);
l_initPosNode->SetAttributeAsFloat ("y", m_position.y);
l_initPosNode->SetAttributeAsFloat ("z", m_position.z);
l_initPosNode->SetAttributeAsFloat ("Qx", m_bodyQ.x);
l_initPosNode->SetAttributeAsFloat ("Qy", m_bodyQ.y);
l_initPosNode->SetAttributeAsFloat ("Qz", m_bodyQ.z);
l_initPosNode->SetAttributeAsFloat ("Qr", m_bodyQ.r);
return true;
}
/**
Actually this method loads a position.
*/
bool KPosition::Read (iDocumentNode* p_parent)
{
SetName (p_parent->GetAttributeValue ("name"));
float l_x = p_parent->GetAttributeValueAsFloat ("x");
float l_y = p_parent->GetAttributeValueAsFloat ("y");
float l_z = p_parent->GetAttributeValueAsFloat ("z");
m_position = csVector3 (l_x, l_y, l_z);
m_bodyQ.x = p_parent->GetAttributeValueAsFloat ("Qx");
m_bodyQ.y = p_parent->GetAttributeValueAsFloat ("Qy");
m_bodyQ.z = p_parent->GetAttributeValueAsFloat ("Qz");
m_bodyQ.r = p_parent->GetAttributeValueAsFloat ("Qr");
return true;
}
See more files for this project here