add virtual mouse

This commit is contained in:
David Rose 2001-12-13 21:37:53 +00:00
parent a1a47f8669
commit 058b835d1b
8 changed files with 269 additions and 11 deletions

View File

@ -16,14 +16,14 @@
clientDialDevice.h clientTrackerDevice.I \ clientDialDevice.h clientTrackerDevice.I \
clientTrackerDevice.h config_device.h dialNode.I dialNode.h \ clientTrackerDevice.h config_device.h dialNode.I dialNode.h \
mouse.h trackerData.I trackerData.h trackerNode.I \ mouse.h trackerData.I trackerData.h trackerNode.I \
trackerNode.h trackerNode.h virtualMouse.h
#define INCLUDED_SOURCES \ #define INCLUDED_SOURCES \
analogNode.cxx buttonNode.cxx clientAnalogDevice.cxx \ analogNode.cxx buttonNode.cxx clientAnalogDevice.cxx \
clientBase.cxx clientButtonDevice.cxx clientDevice.cxx \ clientBase.cxx clientButtonDevice.cxx clientDevice.cxx \
clientDialDevice.cxx clientTrackerDevice.cxx \ clientDialDevice.cxx clientTrackerDevice.cxx \
config_device.cxx dialNode.cxx mouse.cxx trackerData.cxx \ config_device.cxx dialNode.cxx mouse.cxx trackerData.cxx \
trackerNode.cxx trackerNode.cxx virtualMouse.cxx
#define INSTALL_HEADERS \ #define INSTALL_HEADERS \
analogNode.I analogNode.h \ analogNode.I analogNode.h \
@ -37,7 +37,7 @@
config_device.h mouse.h \ config_device.h mouse.h \
dialNode.I dialNode.h \ dialNode.I dialNode.h \
trackerData.I trackerData.h \ trackerData.I trackerData.h \
trackerNode.I trackerNode.h trackerNode.I trackerNode.h virtualMouse.h
#define IGATESCAN all #define IGATESCAN all

View File

@ -29,6 +29,7 @@
#include "dialNode.h" #include "dialNode.h"
#include "mouse.h" #include "mouse.h"
#include "trackerNode.h" #include "trackerNode.h"
#include "virtualMouse.h"
#include <dconfig.h> #include <dconfig.h>
@ -68,4 +69,5 @@ init_libdevice() {
DialNode::init_type(); DialNode::init_type();
MouseAndKeyboard::init_type(); MouseAndKeyboard::init_type();
TrackerNode::init_type(); TrackerNode::init_type();
VirtualMouse::init_type();
} }

View File

@ -6,4 +6,5 @@
#include "mouse.cxx" #include "mouse.cxx"
#include "trackerData.cxx" #include "trackerData.cxx"
#include "trackerNode.cxx" #include "trackerNode.cxx"
#include "virtualMouse.cxx"

View File

@ -17,10 +17,7 @@
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
#ifndef MOUSE_H #ifndef MOUSE_H
#define MOUSE_H #define MOUSE_H
//
////////////////////////////////////////////////////////////////////
// Includes
////////////////////////////////////////////////////////////////////
#include "pandabase.h" #include "pandabase.h"
#include "dataNode.h" #include "dataNode.h"
@ -30,10 +27,6 @@
#include "pointerTo.h" #include "pointerTo.h"
#include "allTransitionsWrapper.h" #include "allTransitionsWrapper.h"
////////////////////////////////////////////////////////////////////
// Defines
////////////////////////////////////////////////////////////////////
const int MIN_MOVE = 2;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Class : MouseAndKeyboard // Class : MouseAndKeyboard

View File

@ -0,0 +1,164 @@
// Filename: virtualMouse.cxx
// Created by: drose (13Dec01)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#include "virtualMouse.h"
TypeHandle VirtualMouse::_type_handle;
TypeHandle VirtualMouse::_pixel_xyz_type;
TypeHandle VirtualMouse::_xyz_type;
TypeHandle VirtualMouse::_button_events_type;
////////////////////////////////////////////////////////////////////
// Function: VirtualMouse::Constructor
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
VirtualMouse::
VirtualMouse(const string &name) :
DataNode(name)
{
_pixel_xyz = new Vec3DataTransition(LPoint3f(0.0f, 0.0f, 0.0f));
_xyz = new Vec3DataTransition(LPoint3f(0.0f, 0.0f, 0.0f));
_button_events = new ButtonEventDataTransition();
_got_mouse_attrib.set_transition(_pixel_xyz_type, _pixel_xyz);
_got_mouse_attrib.set_transition(_xyz_type, _xyz);
_got_mouse_attrib.set_transition(_button_events_type, _button_events);
_no_mouse_attrib.set_transition(_button_events_type, _button_events);
_mouse_x = 0;
_mouse_y = 0;
_win_width = 100;
_win_height = 100;
_mouse_on = false;
_next_button_events = new ButtonEventDataTransition();
}
////////////////////////////////////////////////////////////////////
// Function: VirtualMouse::set_mouse_pos
// Access: Published
// Description: Sets the current mouse pixel location, where (0,0) is
// the upper left, and (width-1, height-1) is the lower
// right pixel of the virtual window.
////////////////////////////////////////////////////////////////////
void VirtualMouse::
set_mouse_pos(int x, int y) {
_mouse_x = x;
_mouse_y = y;
}
////////////////////////////////////////////////////////////////////
// Function: VirtualMouse::set_window_size
// Access: Published
// Description: Sets the size of the "window" in which the mouse
// rolls. This changes the meaning of the values passed
// to set_mouse_pos().
////////////////////////////////////////////////////////////////////
void VirtualMouse::
set_window_size(int width, int height) {
_win_width = width;
_win_height = height;
}
////////////////////////////////////////////////////////////////////
// Function: VirtualMouse::set_mouse_on
// Access: Published
// Description: Sets whether the mouse should appear to be within the
// window or not. If this is true, the mouse is within
// the window; if false, the mouse is not within the
// window (and set_mouse_pos() means nothing).
////////////////////////////////////////////////////////////////////
void VirtualMouse::
set_mouse_on(bool flag) {
_mouse_on = flag;
}
////////////////////////////////////////////////////////////////////
// Function: VirtualMouse::press_button
// Access: Published
// Description: Simulates a mouse or keyboard button being depressed.
// This should be followed up by a call to
// release_button() sometime later (possibly
// immediately).
////////////////////////////////////////////////////////////////////
void VirtualMouse::
press_button(ButtonHandle button) {
_next_button_events->push_back(ButtonEvent(button, true));
}
////////////////////////////////////////////////////////////////////
// Function: VirtualMouse::release_button
// Access: Published
// Description: Simulates the button being released. This should
// follow a previous call to press_button().
////////////////////////////////////////////////////////////////////
void VirtualMouse::
release_button(ButtonHandle button) {
_next_button_events->push_back(ButtonEvent(button, false));
}
////////////////////////////////////////////////////////////////////
// Function: VirtualMouse::transmit_data
// Access: Public, Virtual
// Description:
////////////////////////////////////////////////////////////////////
void VirtualMouse::
transmit_data(AllTransitionsWrapper &data) {
// Swap in the button events, and clear them for next time.
_button_events->swap(_next_button_events);
_next_button_events->clear();
if (_mouse_on) {
// The mouse is within the window.
_pixel_xyz->set_value(LPoint3f(_mouse_x, _mouse_y, 0.0f));
// Scale to range [-1,1]
float xf = (2.0f * (float)_mouse_x) / (float)_win_width - 1.0f;
float yf = 1.0f - (2.0f * (float)_mouse_y) / (float)_win_height;
_xyz->set_value(LPoint3f(xf, yf, 0.0f));
data = _got_mouse_attrib;
} else {
// The mouse isn't within the window.
data = _no_mouse_attrib;
}
}
////////////////////////////////////////////////////////////////////
// Function: VirtualMouse::init_type
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void VirtualMouse::
init_type() {
DataNode::init_type();
register_type(_type_handle, "VirtualMouse",
DataNode::get_class_type());
Vec3DataTransition::init_type();
register_data_transition(_pixel_xyz_type, "PixelXYZ",
Vec3DataTransition::get_class_type());
register_data_transition(_xyz_type, "XYZ",
Vec3DataTransition::get_class_type());
ButtonEventDataTransition::init_type();
register_data_transition(_button_events_type, "ButtonEvents",
ButtonEventDataTransition::get_class_type());
}

View File

@ -0,0 +1,87 @@
// Filename: virtualMouse.h
// Created by: drose (13Dec01)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://www.panda3d.org/license.txt .
//
// To contact the maintainers of this program write to
// panda3d@yahoogroups.com .
//
////////////////////////////////////////////////////////////////////
#ifndef VIRTUALMOUSE_H
#define VIRTUALMOUSE_H
#include "pandabase.h"
#include "dataNode.h"
#include "buttonHandle.h"
#include "buttonEvent.h"
#include "vec3DataTransition.h"
#include "buttonEventDataTransition.h"
#include "pointerTo.h"
#include "allTransitionsWrapper.h"
////////////////////////////////////////////////////////////////////
// Class : VirtualMouse
// Description : Poses as a MouseAndKeyboard object in the datagraph,
// but accepts input from user calls, rather than
// reading the actual mouse and keyboard from an input
// device. The user can write high-level code to put
// the mouse wherever he/she wants, and to insert
// keypresses on demand.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA VirtualMouse : public DataNode {
PUBLISHED:
VirtualMouse(const string &name = "");
void set_mouse_pos(int x, int y);
void set_window_size(int width, int height);
void set_mouse_on(bool flag);
void press_button(ButtonHandle button);
void release_button(ButtonHandle button);
public:
virtual void transmit_data(AllTransitionsWrapper &data);
public:
AllTransitionsWrapper _got_mouse_attrib;
AllTransitionsWrapper _no_mouse_attrib;
PT(Vec3DataTransition) _pixel_xyz;
PT(Vec3DataTransition) _xyz;
PT(ButtonEventDataTransition) _button_events;
static TypeHandle _mods_type;
static TypeHandle _pixel_xyz_type;
static TypeHandle _xyz_type;
static TypeHandle _button_events_type;
private:
int _mouse_x, _mouse_y;
int _win_width, _win_height;
bool _mouse_on;
PT(ButtonEventDataTransition) _next_button_events;
public:
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type();
private:
static TypeHandle _type_handle;
};
#endif

View File

@ -29,6 +29,16 @@
TypeHandle ButtonEventDataTransition::_type_handle; TypeHandle ButtonEventDataTransition::_type_handle;
////////////////////////////////////////////////////////////////////
// Function: ButtonEventDataTransition::swap
// Access: Public
// Description: Swaps the data in the queue with that in the other.
////////////////////////////////////////////////////////////////////
void ButtonEventDataTransition::
swap(ButtonEventDataTransition *other) {
_buttons.swap(other->_buttons);
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: ButtonEventDataTransition::update_mods // Function: ButtonEventDataTransition::update_mods
// Access: Public // Access: Public

View File

@ -54,6 +54,7 @@ public:
INLINE void clear(); INLINE void clear();
INLINE void push_back(const ButtonEvent &event); INLINE void push_back(const ButtonEvent &event);
void swap(ButtonEventDataTransition *other);
void update_mods(ModifierButtons &mods) const; void update_mods(ModifierButtons &mods) const;