Code Search for Developers
 
 
  

klandmarklist.cpp from Spatial Knowledge Experiments at Krugle


Show klandmarklist.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/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 "iutil/document.h"//ADDED


#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 "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 "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 "ksprite3d.h"
#include "kappstate.h"
#include "ske.h"
#include "kutil.h"
#include "klandmark.h"
//Include file for this file.
#include "klandmarklist.h"



SCF_IMPLEMENT_IBASE (KLandmarkList)
  SCF_IMPLEMENTS_INTERFACE (iKXMLWriter)
  SCF_IMPLEMENTS_INTERFACE (iKXMLReader)
SCF_IMPLEMENT_IBASE_END


KLandmarkList::KLandmarkList()
{
  SetName ("");
}

KLandmarkList::~KLandmarkList()
{
}

void KLandmarkList::SetName (const char* p_name)
{
  m_name.AttachNew (new scfString (p_name));
}
const char* KLandmarkList::GetName () const
{
  return m_name->GetData ();
}


size_t KLandmarkList::GetCount () const
{
  return m_landmarks.Length ();
}
 
KLandmark* KLandmarkList::Get (int p_n) const
{
  return m_landmarks.Get (p_n);
}
 
int KLandmarkList::Add (KLandmark* p_obj)
{
  return m_landmarks.Push (p_obj);
}
 
bool KLandmarkList::Remove (KLandmark* p_obj)
{
  if (m_landmarks.DeleteIndex (m_landmarks.Find(p_obj)))
    return true;
  else
    return false;
}

bool KLandmarkList::Remove (int p_n)
{
  KLandmark* l_lm = Get (p_n);
  if (m_landmarks.DeleteIndex (p_n))
    return true;
  else
    return false;
}
  
int KLandmarkList::Find (KLandmark *p_sprite) const
{
  return m_landmarks.Find(p_sprite);
}

KLandmark* KLandmarkList::FindByName (const char *p_name) const
{
  KLandmark* l_lm;
  csString l_string(p_name);
  
  size_t i;
  for (i = 0;i < GetCount (); i++)
  {
    l_lm = Get (i);
    const char* l_string2 = l_lm->GetName ();
    if (l_string.Compare (l_string2))
      return l_lm;
  }//for
  return NULL;
}

void KLandmarkList::RemoveAndDestroyAll ()
{
  KLandmark* l_lm;
  size_t i;
  for (i = 0; i < GetCount (); i++)
  {
    l_lm = Get (i);
    l_lm->Release ();
  }//for

  m_landmarks.DeleteAll ();
}

void KLandmarkList::RemoveAll ()
{
  m_landmarks.DeleteAll ();
}

void KLandmarkList::AttachColliders (iCollideSystem* p_cS)
{
  KLandmark* l_lm;
  size_t i;
  for (i = 0; i < GetCount (); i++)
  {
    l_lm = Get (i);
    l_lm->AttachColliders (p_cS);
  }//for
}

void KLandmarkList::DetachColliders (iCollideSystem* p_cS)
{
  KLandmark* l_lm;
  size_t i;
  for (i = 0; i < GetCount (); i++)
  {
    l_lm = Get (i);
    l_lm->DetachColliders (p_cS);
  }//for
}



//
//iKXMLReader/Writer interfaces.
bool KLandmarkList::Write (iDocumentNode* p_node) const
{
  csRef<iDocumentNode> l_landmarksListNode = 
    p_node->CreateNodeBefore (CS_NODE_ELEMENT, NULL);
  l_landmarksListNode->SetValue ("landmarks_list");
  l_landmarksListNode->SetAttribute ("name", m_name->GetData ());

  int l_count = GetCount ();
  int i;
  for (i = 0; i < l_count; i++)
  {
    KLandmark* l_lm = Get (i);//get the landmark.

    //
    //create the node for the landmark.
    csRef<iDocumentNode> l_lmNode = l_landmarksListNode->CreateNodeBefore 
      (CS_NODE_ELEMENT, NULL);
    l_lmNode->SetValue ("landmark");
    l_lmNode->SetAttribute ("name", l_lm->GetName ());
    csVector3 l_pos = l_lm->GetPosition ();
    l_lmNode->SetAttributeAsFloat ("x", l_pos.x);
    l_lmNode->SetAttributeAsFloat ("y", l_pos.y);
    l_lmNode->SetAttributeAsFloat ("z", l_pos.z);
    float l_yrotation = l_lm->GetYRotation ();
    l_lmNode->SetAttributeAsFloat ("yrotation", l_yrotation);

    /*the tree is:   mesh   ...  mesh
                      ^           ^
                      |           |
                  KSprite3D    KSprite3D
                          ^    ^
                          |    |
                         KLandmark      
    */
    csRef<iObjectIterator> l_oI = l_lm->GetIterator ();
    int j = 0;
    while (l_oI->HasNext ())
    {
      KSprite3D* l_s3d = (KSprite3D*) (l_oI->Next ());
      
      csVector3 l_offset = l_lm->GetOffset (j);
      float l_xScale = l_s3d->GetXScale ();
      float l_yScale = l_s3d->GetYScale ();
      float l_zScale = l_s3d->GetZScale ();
      float l_yRotation = l_s3d->GetYRotation ();
      
      //create a new landmark node.      
      csRef<iDocumentNode> l_s3dNode = l_lmNode->CreateNodeBefore 
        (CS_NODE_ELEMENT, NULL);
      l_s3dNode->SetValue ("sprite3d");
      l_s3dNode->SetAttribute ("name", l_s3d->GetName ());
      l_s3dNode->SetAttribute ("model", l_s3d->GetModelName ()->GetData ());
      l_s3dNode->SetAttribute ("materialname", l_s3d->GetMaterialName ());
      l_s3dNode->SetAttributeAsFloat ("yrotation", l_yRotation);
      l_s3dNode->SetAttributeAsFloat ("xoffset", l_offset.x);
      l_s3dNode->SetAttributeAsFloat ("yoffset", l_offset.y);
      l_s3dNode->SetAttributeAsFloat ("zoffset", l_offset.z);
      l_s3dNode->SetAttributeAsFloat ("xscale", l_xScale);
      l_s3dNode->SetAttributeAsFloat ("yscale", l_yScale);
      l_s3dNode->SetAttributeAsFloat ("zscale", l_zScale);
      
      j++;
    }//while
  }//for
  return true;
}
bool KLandmarkList::Read (iDocumentNode* p_node)
{
  //Remove all the landmarks from the engine.
  RemoveAndDestroyAll ();
  
  //Read and set the name.
  SetName (p_node->GetAttributeValue ("name"));

  csRef<iDocumentNodeIterator> l_it2 = p_node->GetNodes ();
  while (l_it2->HasNext ())
  {
    csRef<iDocumentNode> l_lmNode = l_it2->Next ();
    if (l_lmNode->GetType () != CS_NODE_ELEMENT) 
      continue;
    const char* value = l_lmNode->GetValue ();
    if (!strcmpi(value,"landmark"))
    {
      //
      //Create and read the landmark from the XML file.
      csRef<KLandmark> l_lm;
      l_lm.AttachNew (new KLandmark ());
      l_lm->Read (l_lmNode);
      
      Add (l_lm);//Add the landmark to the list!
      
      l_lm->SetSector (g_ske->m_world);
    }//if
  }//while

  return true;
}





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