Code Search for Developers
 
 
  

ksign.cpp from Spatial Knowledge Experiments at Krugle


Show ksign.cpp 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.
*/

#include "cssysdef.h"

#include "csutil/sysfunc.h"
#include "csutil/cmdhelp.h"
#include "csutil/cscolor.h"
#include "csutil/cmdhelp.h"
#include "csutil/cspmeter.h"
#include "csutil/csstring.h"
#include "csutil/scfstr.h"

#include "cstool/csview.h"
#include "cstool/initapp.h"
#include "cstool/collider.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 "imesh/sprite2d.h"
#include "imesh/ball.h"
#include "imesh/object.h"

#include "iengine/mesh.h"
#include "iengine/engine.h"
#include "iengine/sector.h"
#include "iengine/mesh.h"
#include "iengine/sector.h"
#include "iengine/engine.h"
#include "iengine/camera.h"
#include "iengine/light.h"
#include "iengine/texture.h"
#include "iengine/movable.h"
#include "iengine/material.h"

#include "igraphic/imageio.h"

#include "iutil/vfs.h"
#include "iutil/eventq.h"
#include "iutil/event.h"
#include "iutil/eventh.h"
#include "iutil/objreg.h"
#include "iutil/csinput.h"
#include "iutil/virtclk.h"
#include "iutil/plugin.h"
#include "iutil/string.h"
#include "iutil/comp.h"

#include "imesh/thing.h"
#include "imesh/object.h"
#include "imesh/sprite3d.h"
#include "imesh/genmesh.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/tri.h"
#include "csgeom/quaterni.h"
#include "csgeom/transfrm.h"
#include "csgeom/math3d_d.h"
#include "csgeom/math3d.h"

#include "igeom/polymesh.h"

#include "iaws/aws.h"
#include "iaws/awscnvs.h"


#include "ske.h"
#include "kcamera.h"
#include "kutil.h"
//Includes for this file.
#include "ksign.h"


KSign::KSign ()
{
  m_g3d = CS_QUERY_REGISTRY (g_objReg, iGraphics3D);
  m_engine = CS_QUERY_REGISTRY (g_objReg, iEngine);
  m_fontServer = CS_QUERY_REGISTRY (g_objReg, iFontServer);
}

KSign::~KSign ()
{
}

void KSign::Initialize ()
{
	int i;
  //
  //Load the texture for the states!
  m_lookTowards = SKE::LoadMaterial ("look_towards", 
    "/SKE/texture/look_towards.gif");
  m_timeExpired = SKE::LoadMaterial ("time_expired", 
    "/SKE/texture/time_expired.gif");
  m_wrongWay = SKE::LoadMaterial ("wrong_way", 
    "/SKE/texture/wrong_way.gif");
  m_pathCompleted = SKE::LoadMaterial ("path_completed", 
    "/SKE/texture/path_completed.gif");
  m_targetReached = SKE::LoadMaterial ("target_reached", 
    "/SKE/texture/target_reached.gif");
  m_missionTerminated = SKE::LoadMaterial ("mission_terminated",
    "/SKE/texture/mission_terminated.gif");

  csRef<iGraphics2D> l_g2d = m_g3d->GetDriver2D ();

  int l_height = 128;
  int l_width = 128;
  csColor transp (1,1,1);

  /*csRef<iTextureWrapper> l_textWrap = m_engine->CreateBlackTexture 
    ("timeExpired", l_width, l_height, &transp , CS_TEXTURE_3D);

  m_timeExpired = m_engine->CreateMaterial ("timeExpired", l_textWrap);*/
  /*m_timeExpired->Register (m_g3d->GetTextureManager ());

  m_g3d->SetRenderTarget (m_timeExpired->GetMaterialHandle()->GetTexture());
  
  // save engine context.  I thought this is what keeps this stuff from showing on screen
  iTextureHandle *l_oldContext = m_engine->GetContext ();
  m_engine->SetContext (m_timeExpired->GetMaterialHandle()->GetTexture());
  // actually draw the texture now
  m_g3d->BeginDraw (CSDRAW_2DGRAPHICS);
  l_g2d->ClearAll (l_g2d->FindRGB (255, 255, 255)); // will be transparent
    
  csRef<iFont> l_font;
  l_font = m_fontServer->LoadFont ("/K/font/KSignFont.csf");
  l_g2d->Write (l_font, 0, 20, l_g2d->FindRGB (50, 50, 200), 
                          -1, "Tempo Scaduto!");
  m_g3d->FinishDraw();
  m_engine->SetContext (l_oldContext);*/

  //
  //Create the general mesh.
  csRef<iMeshFactoryWrapper> m_genFactW = g_ske->m_engine->
    CreateMeshFactory ("crystalspace.mesh.object.genmesh", "genFact");
  
  csRef<iGeneralFactoryState> l_genFactState = SCF_QUERY_INTERFACE (
    m_genFactW->GetMeshObjectFactory (), iGeneralFactoryState);
  
  //
  //Put the right geometry in the factory.
  int dim = 1.0f;
  l_genFactState->SetVertexCount (4);
  csVector3* verts = l_genFactState->GetVertices ();
  verts[0].Set (-dim, dim, 0);
  verts[1].Set (dim, dim, 0);
  verts[2].Set (dim, -dim, 0);
  verts[3].Set (-dim, -dim, 0);
  
  csVector2* texels = l_genFactState->GetTexels ();
  texels[0].Set (0, 0);
  texels[1].Set (1, 0);
  texels[2].Set (1, 1);
  texels[3].Set (0, 1);
  
  l_genFactState->SetTriangleCount (2);
  csTriangle* tris = l_genFactState->GetTriangles ();
  tris[0] = csTriangle (0, 1, 2);
  tris[1] = csTriangle (2, 3, 0);
  
  l_genFactState->CalculateNormals ();
  
  
  //
  //Create the mesh object by the factory.
  m_genMW =m_genFactW->CreateMeshWrapper ();
  
  
  m_genMW->SetZBufMode (CS_ZBUF_FILL);//Just fill the zbuffer.
  //Set priority to alpha.
  m_genMW->SetRenderPriority (g_ske->m_engine->GetRenderPriority ("alpha"));
  
  //
  //Get the state interface from the mesh object created.
  m_genMeshState = SCF_QUERY_INTERFACE (m_genMW->GetMeshObject (),
    iGeneralMeshState);
  
  m_genMeshState->SetMixMode (CS_FX_SETALPHA (0.1f));
  m_genMeshState->SetLighting (false);
  
  //
  //Init to initial state.
  SetDisplay (NONE);
}

void KSign::SetupFrame (KCamera* p_kcam, float p_msecs)
{
  csOrthoTransform l_oT = p_kcam->GetCamera ()->GetTransform ();
  csVector3 l_camPos = l_oT.GetOrigin ();
  
  csVector3 l_zAxis (0, 0, 1.0f);
  csVector3 l_yAxis (0, 1.0f, 0);
  csVector3 l_pos = l_oT.This2OtherRelative (l_zAxis );
  csVector3 l_up = l_oT.This2OtherRelative (l_yAxis );
  
  m_genMW->GetMovable ()->SetTransform (l_oT.GetT2O ());
  m_genMW->GetMovable ()->SetPosition (l_camPos + l_pos * 2.0f);
  m_genMW->GetMovable ()->UpdateMove ();
}

void KSign::SetDisplay (KSIGN_STATE p_mode)
{
  switch (p_mode)
  {
  case NONE:
    {
      m_genMW->GetMovable ()->SetSector (g_ske->m_hiddenWorld);
      m_genMW->GetMovable ()->UpdateMove ();
      break;
    }//
  case LOOK_TOWARDS:
    {
      m_genMeshState->SetMaterialWrapper (m_lookTowards);
      
      m_genMW->GetMovable ()->SetSector (g_ske->m_world);
      m_genMW->GetMovable ()->UpdateMove ();
      break;
    }
  case TIME_EXPIRED:
    {
      m_genMeshState->SetMaterialWrapper (m_timeExpired);
      
      m_genMW->GetMovable ()->SetSector (g_ske->m_world);
      m_genMW->GetMovable ()->UpdateMove ();
      break;
    }
  case WRONG_WAY:
    {
      m_genMeshState->SetMaterialWrapper (m_wrongWay);
      
      m_genMW->GetMovable ()->SetSector (g_ske->m_world);
      m_genMW->GetMovable ()->UpdateMove ();
      break;
    }
  case TARGET_REACHED:
    {
      m_genMeshState->SetMaterialWrapper (m_targetReached);
      
      m_genMW->GetMovable ()->SetSector (g_ske->m_world);
      m_genMW->GetMovable ()->UpdateMove ();
      break;
    }
  case PATH_COMPLETED:
    {
      m_genMeshState->SetMaterialWrapper (m_pathCompleted);
      
      m_genMW->GetMovable ()->SetSector (g_ske->m_world);
      m_genMW->GetMovable ()->UpdateMove ();
      break;
    }//case
  case MISSION_TERMINATED:
    {
      m_genMeshState->SetMaterialWrapper (m_missionTerminated);
      
      m_genMW->GetMovable ()->SetSector (g_ske->m_world);
      m_genMW->GetMovable ()->UpdateMove ();
      break;
    }//case
  default:
    {
      SKE::Report (CS_REPORTER_SEVERITY_ERROR,
        "Error: KSign state not consistent!");
      break;
    }//default
  }//switch
}




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