Revision: 7519
http://playerstage.svn.sourceforge.net/playerstage/?rev=7519&view=rev
Author: hsujohnhsu
Date: 2009-03-17 01:35:30 +0000 (Tue, 17 Mar 2009)
Log Message:
-----------
update user interface, right click -> select body, left click -> select model.
right drag -> apply force, left drag -> apply torque.
Modified Paths:
--------------
code/gazebo/branches/ogre-1.4.9/server/gui/GLWindow.cc
code/gazebo/branches/ogre-1.4.9/server/gui/GLWindow.hh
Modified: code/gazebo/branches/ogre-1.4.9/server/gui/GLWindow.cc
===================================================================
--- code/gazebo/branches/ogre-1.4.9/server/gui/GLWindow.cc 2009-03-17
01:32:39 UTC (rev 7518)
+++ code/gazebo/branches/ogre-1.4.9/server/gui/GLWindow.cc 2009-03-17
01:35:30 UTC (rev 7519)
@@ -35,6 +35,7 @@
#include "Param.hh"
#include "Entity.hh"
+#include "Body.hh"
#include "OgreCamera.hh"
#include "OgreCreator.hh"
#include "Simulator.hh"
@@ -62,9 +63,9 @@
{
this->end();
- this->moveAmount = 1.0;
+ this->moveAmount = 0.1;
this->moveScale = 1;
- this->rotateAmount = 0.5;
+ this->rotateAmount = 0.1;
this->directionVec.x = 0;
this->directionVec.y = 0;
@@ -143,6 +144,17 @@
this->activeCamera->UpdateCam();
else
this->userCamera->Update();
+
+ // continuously apply force to selected body
+ Body *body = Simulator::Instance()->GetSelectedBody();
+ if (this->rightMousePressed && body)
+ {
+ body->SetForce(this->forceVec);
+ }
+ if (this->leftMousePressed && body)
+ {
+ body->SetTorque(this->torqueVec);
+ }
}
@@ -169,10 +181,12 @@
{
case FL_LEFT_MOUSE:
this->leftMousePressed = true;
+ //this->torqueVec = Vector3(0,0,0); // not necessary
break;
case FL_RIGHT_MOUSE:
this->rightMousePressed = true;
+ //this->forceVec = Vector3(0,0,0); // not necessary
break;
case FL_MIDDLE_MOUSE:
@@ -204,10 +218,21 @@
if (!this->mouseDrag)
{
Entity *ent = OgreAdaptor::Instance()->GetEntityAt(this->activeCamera,
this->mousePos);
+ Body *bod = OgreAdaptor::Instance()->GetBodyAt(this->activeCamera,
this->mousePos);
+ switch (Fl::event_button())
+ {
+ case FL_LEFT_MOUSE:
+ if (ent) Simulator::Instance()->SetSelectedEntity( ent );
+ this->mouseOriginPos = Vector2<int>( Fl::event_x(), Fl::event_y() );
+ break;
- if (ent)
- {
- Simulator::Instance()->SetSelectedEntity( ent );
+ case FL_RIGHT_MOUSE:
+ if (bod) Simulator::Instance()->SetSelectedBody( bod );
+ this->mouseOriginPos = Vector2<int>( Fl::event_x(), Fl::event_y() );
+ break;
+
+ case FL_MIDDLE_MOUSE:
+ break;
}
}
@@ -220,36 +245,158 @@
{
if (this->activeCamera && this->activeCamera->GetUserMovable())
{
- Vector2<int> d = this->mousePos - this->prevMousePos;
+ Vector2<int> drag = this->mousePos - this->prevMousePos;
+
+ double vpw = this->activeCamera->GetViewportWidth();
+ double vph = this->activeCamera->GetViewportHeight();
+ Vector3 camUp = this->activeCamera->GetUp();
+ Vector3 camRight = this->activeCamera->GetRight();
+
if (this->leftMousePressed)
{
- this->activeCamera->RotateYaw(DTOR(-d.x * this->rotateAmount));
- this->activeCamera->RotatePitch(DTOR(d.y * this->rotateAmount));
+ Model *model =
dynamic_cast<Model*>(Simulator::Instance()->GetSelectedEntity());
+ Body *body = Simulator::Instance()->GetSelectedBody();
+ if (model || body)
+ {
+ if (model)
+ {
+ //
+ // interactively change rotation pose to selected item, rotate about
axis perpendicular to view port plane
+ //
+ Pose3d modelPose = model->GetPose();
+
+ double distance = (modelPose.pos -
this->activeCamera->GetCameraPosition()).GetLength();
+ double scaleX = distance * tan
(this->activeCamera->GetHFOV().GetAsRadian() / 2.0f ) * 2.0f;
+ double scaleY = distance * tan
(this->activeCamera->GetVFOV().GetAsRadian() / 2.0f ) * 2.0f;
+
+ Vector3 camRay = camRight.GetCrossProd(camUp); // axis
perpendicular to view port plane
+ Quatern yawDragQ;
yawDragQ.SetFromAxis(camRay.x,camRay.y,camRay.z,drag.x/vpw*scaleX);
+
+ modelPose.rot = yawDragQ * modelPose.rot;
+ model->SetPose(modelPose);
+ Vector3 eul = modelPose.rot.GetAsEuler();
+ std::cout << "set euler angles r(" << eul.x << ") p(" << eul.y << ")
to model (" << model->GetName() << ")" << std::endl;
+ }
+ if (body)
+ {
+ //
+ // interactively set torque selected item
+ //
+ Pose3d bodyPose = body->GetPose();
+
+ double distance = (bodyPose.pos -
this->activeCamera->GetCameraPosition()).GetLength();
+ double scaleX = distance * tan
(this->activeCamera->GetHFOV().GetAsRadian() / 2.0f ) * 2.0f;
+ double scaleY = distance * tan
(this->activeCamera->GetVFOV().GetAsRadian() / 2.0f ) * 2.0f;
+
+ Quatern qUp;
qUp.SetFromAxis(camUp.x,camUp.y,camUp.z,(double)drag.x/vpw*scaleX);
+ Quatern qRight;
qRight.SetFromAxis(camRight.x,camRight.y,camRight.z,(double)drag.y/vpw*scaleY);
+ Quatern upRightDragQ = qUp * qRight;
+
+ double torqueScale = 10000.0;
+ this->torqueVec = upRightDragQ.GetAsEuler()*torqueScale;
+ body->SetTorque(this->torqueVec);
+ std::cout << "set euler torques (" << this->torqueVec << ") to body
(" << body->GetName() << ")" << std::endl;
+ }
+ }
+ else
+ {
+ //
+ // interactively rotate view
+ //
+ this->activeCamera->RotateYaw(DTOR(-drag.x * this->rotateAmount));
+ this->activeCamera->RotatePitch(DTOR(drag.y * this->rotateAmount));
+ }
}
else if (this->rightMousePressed)
{
Model *model =
dynamic_cast<Model*>(Simulator::Instance()->GetSelectedEntity());
- if (model)
+ Body *body = Simulator::Instance()->GetSelectedBody();
+ if (model || body)
{
- Pose3d pose = model->GetPose();
- pose.pos.y -= d.x * 0.05;
- pose.pos.x -= d.y * 0.05;
- model->SetPose(pose);
+ if (model)
+ {
+ //
+ // interactively set pose to selected model
+ //
+ Pose3d modelPose = model->GetPose();
+ double distance = (modelPose.pos -
this->activeCamera->GetCameraPosition()).GetLength();
+ double scaleX = distance * tan
(this->activeCamera->GetHFOV().GetAsRadian() / 2.0f ) * 2.0f;
+ double scaleY = distance * tan
(this->activeCamera->GetVFOV().GetAsRadian() / 2.0f ) * 2.0f;
+ Vector3 moveVector = (camRight*drag.x/vpw*scaleX -
camUp*drag.y/vph*scaleY);
+ // std::cout << " vpw " << vpw
+ // << " vph " << vph
+ // << " distance " << distance
+ // << " scaleX " << scaleX
+ // << " scaleY " << scaleY
+ // << std::endl;
+
+ modelPose.pos += moveVector;
+ model->SetPose(modelPose);
+ std::cout << "set pose (" << modelPose << ") to model (" <<
model->GetName() << ")" << std::endl;
+ }
+ if (body)
+ {
+ //
+ // interactively set force to selected body
+ //
+ Pose3d bodyPose = body->GetPose();
+ double distance = (bodyPose.pos -
this->activeCamera->GetCameraPosition()).GetLength();
+ double scaleX = distance * tan
(this->activeCamera->GetHFOV().GetAsRadian() / 2.0f ) * 2.0f;
+ double scaleY = distance * tan
(this->activeCamera->GetVFOV().GetAsRadian() / 2.0f ) * 2.0f;
+ Vector3 moveVector = (camRight*drag.x/vpw*scaleX -
camUp*drag.y/vph*scaleY);
+ // std::cout << " vpw " << vpw
+ // << " vph " << vph
+ // << " distance " << distance
+ // << " scaleX " << scaleX
+ // << " scaleY " << scaleY
+ // << std::endl;
+
+ double forceScale = 10000.0;
+ this->forceVec = moveVector*forceScale;
+ std::cout << "set body force to" << this->forceVec << " to body " <<
body->GetName() << std::endl;
+ }
}
else
{
- Vector2<int> d = this->mousePos - this->prevMousePos;
+ //
+ // interactively pan view
+ //
this->directionVec.x = 0;
- this->directionVec.y = d.x * this->moveAmount;
- this->directionVec.z = d.y * this->moveAmount;
+ this->directionVec.y = drag.x * this->moveAmount;
+ this->directionVec.z = drag.y * this->moveAmount;
}
}
else if (this->middleMousePressed)
{
- Vector2<int> d = this->mousePos - this->prevMousePos;
- this->directionVec.x = d.y * this->moveAmount;
- this->directionVec.y = 0;
- this->directionVec.z = 0;
+ Body *body = Simulator::Instance()->GetSelectedBody();
+ if (body)
+ {
+ //
+ // interactively set pose to selected body
+ //
+ Pose3d bodyPose = body->GetPose();
+
+ //Vector2<double> ddrag((double)drag.x,(double)drag.y);
+ //if (drag.x*drag.x + drag.y*drag.y > 0)
+ // ddrag.Normalize();
+ //Vector3 dragVector = (camRight*ddrag.x - camUp*ddrag.y);
+ //bodyPose.pos += dragVector*0.05;
+
+ double distance = (bodyPose.pos -
this->activeCamera->GetCameraPosition()).GetLength();
+ double scaleX = distance * tan
(this->activeCamera->GetHFOV().GetAsRadian() / 2.0f ) * 2.0f;
+ double scaleY = distance * tan
(this->activeCamera->GetVFOV().GetAsRadian() / 2.0f ) * 2.0f;
+ Vector3 moveVector = (camRight*drag.x/vpw*scaleX -
camUp*drag.y/vph*scaleY);
+
+ bodyPose.pos += moveVector;
+ body->SetPose(bodyPose);
+ std::cout << "set pose (" << bodyPose << ") to Body (" <<
body->GetName() << ")" << std::endl;
+ }
+ else
+ {
+ this->directionVec.x = drag.y * this->moveAmount;
+ this->directionVec.y = 0;
+ this->directionVec.z = 0;
+ }
}
}
@@ -261,12 +408,33 @@
void GLWindow::HandleMouseWheel(int dx, int dy)
{
Model *model =
dynamic_cast<Model*>(Simulator::Instance()->GetSelectedEntity());
- if (model)
+ Body *body = Simulator::Instance()->GetSelectedBody();
+
+ if (model || body)
{
- Pose3d pose = model->GetPose();
- pose.pos.z += dy * 0.05;
- model->SetPose(pose);
+ // FIXME: old
+ if (model)
+ {
+ Pose3d pose = model->GetPose();
+ pose.pos.z += dy * 0.05;
+ model->SetPose(pose);
+ std::cout << "set pose z(" << pose.pos.z << ") to model (" <<
model->GetName() << ")" << std::endl;
+ }
+ // FIXME: old
+ if (body)
+ {
+ Pose3d pose = body->GetPose();
+ pose.pos.z += dy * 0.05;
+ body->SetPose(pose);
+ std::cout << "set pose z(" << pose.pos.z << ") to body (" <<
body->GetName() << ")" << std::endl;
+ }
}
+ else if (this->activeCamera && this->activeCamera->GetUserMovable())
+ {
+ this->directionVec.x -= 50.0 * dy * this->moveAmount;
+ this->directionVec.y = 0;
+ this->directionVec.z = 0;
+ }
}
@@ -309,6 +477,25 @@
this->moveAmount *= 0.5;
break;
+ case XK_j:
+ this->forceVec.z -= 100*this->moveAmount;
+ break;
+ case XK_k:
+ this->forceVec.z += 100*this->moveAmount;
+ break;
+ case XK_h:
+ this->forceVec.y -= 100*this->moveAmount;
+ break;
+ case XK_l:
+ this->forceVec.y += 100*this->moveAmount;
+ break;
+ case XK_x:
+ this->forceVec.x += 100*this->moveAmount;
+ break;
+ case XK_z:
+ this->forceVec.x -= 100*this->moveAmount;
+ break;
+
case XK_Up:
case XK_w:
this->directionVec.x += this->moveAmount;
Modified: code/gazebo/branches/ogre-1.4.9/server/gui/GLWindow.hh
===================================================================
--- code/gazebo/branches/ogre-1.4.9/server/gui/GLWindow.hh 2009-03-17
01:32:39 UTC (rev 7518)
+++ code/gazebo/branches/ogre-1.4.9/server/gui/GLWindow.hh 2009-03-17
01:35:30 UTC (rev 7519)
@@ -40,6 +40,7 @@
#include <FL/Fl_Gl_Window.H>
#include "Gui.hh"
+#include "Pose3d.hh"
#include "Vector3.hh"
#include "Vector2.hh"
@@ -139,6 +140,9 @@
private: bool middleMousePressed;
private: Vector2<int> prevMousePos;
private: Vector2<int> mousePos;
+ private: Vector2<int> mouseOriginPos; // for applying external forces
+ private: Vector3 forceVec; // for applying external forces
+ private: Vector3 torqueVec; // for applying external forces
private: std::map<int,int> keys;
private: double lastUpdateTime;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit