Code Search for Developers
 
 
  

kdragmanager.cpp from Spatial Knowledge Experiments at Krugle


Show kdragmanager.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/dirtyaccessarray.h"
#include "csutil/xmltiny.h"
#include "csutil/array.h"
#include "csutil/event.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 "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 "ksprite3d.h"
#include "ske.h"
#include "korientation.h"
#include "kcamera.h"
#include "kblock.h"
#include "kmap.h"
#include "kblockid.h"
#include "kflags.h"
#include "kwireframe.h"
#include "kappstate.h"
#include "klandmark.h"
#include "klandmarklist.h"
#include "kutil.h"
#include "kcursor3d.h"
#include "kpath.h"
#include "kplayer.h"
#include "klight.h"
#include "kxmlhelper.h"



//Includes for this file.
#include "ikdraggable.h"
#include "kdragmanager.h"


//-----------------------------------------------------------------------
SCF_IMPLEMENT_IBASE (KDragManager)
  SCF_IMPLEMENTS_INTERFACE (iEventHandler)
SCF_IMPLEMENT_IBASE_END


KDragManager::KDragManager ()
{ 
  SCF_CONSTRUCT_IBASE (0);

  //
  //Register itself in the CS event queue.
  csRef<iEventQueue> l_eQ = CS_QUERY_REGISTRY (g_objReg, iEventQueue);
  CS_ASSERT (l_eQ != 0);
  l_eQ->RegisterListener (this, CSMASK_Command);
}

KDragManager::~KDragManager ()
{
  csRef<iEventQueue> l_eQ = CS_QUERY_REGISTRY (g_objReg, iEventQueue);
  CS_ASSERT (l_eQ != 0);
  l_eQ->RemoveListener (this);
}

bool KDragManager::HandleEvent (iEvent& p_e) 
{
  if (p_e.Type == csevCommand && csCommandEventHelper::GetCode (&p_e) == cscmdDragStart)
  {
    bool l_tr = true;;
    if (csEventErrNone != p_e.Retrieve (KDM_TRANSLATING_KEY, l_tr))
      l_tr = false;
    bool l_rot = true;
    if (csEventErrNone != p_e.Retrieve (KDM_ROTATING_KEY, l_rot))
      l_rot = false;
    CS_ASSERT (l_rot ^ l_tr);
    DRAG_TYPE l_dT = l_tr ? TRANSLATION : ROTATION;

    int l_mouseX, l_mouseY;
    p_e.Retrieve (KDM_XAXIS_KEY, l_mouseX);
    p_e.Retrieve (KDM_YAXIS_KEY, l_mouseY);
    
    //
    //Transform the point from (l_mouseX, l_mouseY) to (x', y', 1)
    csVector3 l_v;
    csVector2 l_p (l_mouseX, g_ske->m_kcam->GetCamera ()->GetShiftY () * 2 -
      l_mouseY);
    
    g_ske->m_kcam->GetCamera ()->InvPerspective (l_p, 1.0f, l_v);//z=1.0f is correct.
    csVector3 l_directionW = g_ske->m_kcam->GetCamera ()->
      GetTransform ().This2Other (l_v);
    csVector3 l_eyeW = g_ske->m_kcam->GetCamera ()->
      GetTransform ().GetO2TTranslation ();
    
    csVector3 l_hitPoint;
    
    iMeshWrapper* l_mesh = g_ske->HitMeshWrapper (l_eyeW, l_directionW,
      l_hitPoint);

    m_dragged = (l_mesh ? CS_GET_CHILD_OBJECT (l_mesh->QueryObject (),
      iKDraggable) : 0);
    
    if (m_dragged && m_dragged->Supports (l_dT))
    {
      g_ske->m_cursor->SetVisible (true);
      g_ske->m_cursor->Track (m_dragged->GetMeshWrappers (), true);
    
      m_dragged->GetDragHandler ()->Drag (l_mouseX, 
        l_mouseY, l_hitPoint, l_dT);
    }//if
    else
      m_dragged = false;
  }//if
  else if (p_e.Type == csevCommand && csCommandEventHelper::GetCode (&p_e) == cscmdDragEnd)
  {
    int l_mouseX, l_mouseY;
    p_e.Retrieve (KDM_XAXIS_KEY,l_mouseX);
    p_e.Retrieve (KDM_YAXIS_KEY,l_mouseY);
    
    if (m_dragged)
    {
      m_dragged->GetDragHandler ()->Undrag (l_mouseX, l_mouseY);
      
      g_ske->m_cursor->SetVisible (false);
      g_ske->m_cursor->Untrack ();
      
      m_dragged = 0;
    }//if
  }//else if
  else if (p_e.Type == csevCommand && csCommandEventHelper::GetCode (&p_e) == cscmdDragging)
  {
    int l_mouseX, l_mouseY;

    p_e.Retrieve (KDM_XAXIS_KEY, l_mouseX);
    p_e.Retrieve (KDM_YAXIS_KEY, l_mouseY);
    
    if (m_dragged)
    {
      m_dragged->GetDragHandler ()->HandleDrag (l_mouseX, l_mouseY);
    }//if
  }//else if
  
  return true;
};




/*class Base
{};

class A: public Base
{};

class B:public Base
{};


void bar (A* p)
{}


void bar (B* p)
{}

void foo ()
{
  A * l;
  Base* k = l;
  bar (k);
}*/




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