Capture mouse motion

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
samhwang
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Mar 09, 2005 3:54 pm

Capture mouse motion

Post by samhwang » Wed Mar 16, 2005 2:43 pm

I want to record the orbit of a mouse movement when left buttion is pressed and until it is released. Similar to the presudo-code below:

void OnLeftDown(wxEvent &e)
{
recordMotion = true;
count = 0;
}

void OnLeftUp(wxEvent &e)
{
recordMotion = false;
drawOrbit();
}

void OnMotion(wxEvent &e)
{
if(recordMotion)
{
orbit_x[count] = e.GetX();
orbit_y[count] = e.GetY();
}
}

I don't know how to manage the array orbit_x[] and orbit_y[] since I don't know how to confine thier size, is there a flexible storage solution such as Vector of Java in C++? Or is there any previous efforts I can study with?

Thanks ahead!

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Wed Mar 16, 2005 3:33 pm

OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

samhwang
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Mar 09, 2005 3:54 pm

Post by samhwang » Wed Mar 16, 2005 4:15 pm

Thanks upCASE!
I happen to know that of wxList
http://www.wxwidgets.org/manuals/2.4.2/wx232.htm
But I got some errors when following its example:

C:\image\image.cpp(134) : error C2664: 'void __thiscall wxDCBase::DrawPolygon(const class wxList *,int,int,int)' : cannot convert parameter 1 from 'class PointList' to 'const class wxList *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.

image.exe - 1 error(s), 0 warning(s)

My definition is:
WX_DECLARE_LIST(wxPoint, PointList);
#include <wx/listimpl.cpp>
WX_DEFINE_LIST(PointList);

What are the mistakes?
Thank you!

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Wed Mar 16, 2005 4:37 pm

Hi!
You could try calling DrawPolygon(&myPointList...).

But I'd suggest to either use wxArray, or pass a pointer to the first node of the list (and get the subsequent nodes with node->GetNext() in the function). The node type should be wxPointListNode.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

samhwang
In need of some credit
In need of some credit
Posts: 9
Joined: Wed Mar 09, 2005 3:54 pm

Post by samhwang » Wed Mar 16, 2005 5:48 pm

Hi, I received this confused message:

C:\image\image.cpp(167) : error C2664: 'class wxObjectListNode *__thiscall wxObjectList::Append(class wxObject *)' : cannot convert parameter 1 from 'class wxPoint *' to 'class wxObject *'

Isn't wxPoint derived from wxObject?

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Thu Mar 17, 2005 7:00 am

Hi!
Do you mind posting parts of your code? It would make "debugging" easier...
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

geon
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Tue Sep 07, 2004 4:10 pm
Location: Sweden, Uppsala

Post by geon » Thu Mar 17, 2005 11:10 am

This is how I handle my 3d viewport rotation. Camera.Orbit(float x, float y) implements the rotation itself, depending on the desired rotation model.

Code: Select all

void cViewPort::OnMouse(wxMouseEvent& event){
  static int MouseLastX = 0;
  static int MouseLastY = 0;

  if(event.Dragging()){
    const float OrbitRate = 3.5;
    Camera.Orbit((event.GetX()-MouseLastX)/(GetSize().GetX()+.1)*OrbitRate, (event.GetY()-MouseLastY)/(GetSize().GetX()+.1)*OrbitRate);
  }


  if(event.GetWheelRotation()){
    Camera.Fov(Camera.Fov()/pow(2, -event.GetWheelRotation()/500.0));
  }


  // Save mouse position.
  MouseLastX = event.GetX();
  MouseLastY = event.GetY();

  // Update the view.
  Refresh(FALSE);
}

Post Reply