请教一个菜问题,各位请帮忙!#include
#include
#include
#include
#include
#include
#include // track memory leaks
vuAllocTracer m_allocTracer;// we need to derive our application class from the vpInputSourceBoolean and
// vpTimer subscriber classes so we can be notified of mouse button presses
// and timer expiration events
class myApp : public vpApp, public vpInputSourceBoolean::Subscriber,
public vpTimer::Subscriber
{public: /**
* Constructor
*/
myApp()
{} /**
* Destructor
*/
~myApp()
{
// unreference member variables which cache Vega Prime class instances
m_tank->unref();
}
/**
* Configure my app
*/
int configure() { // pre-configuration // configure vega prime system first
vpApp::configure(); // post-configuration // Increase the reference count by one for all member variables which
// cache the Vega Prime class instances.
//
// All VSG/Vega Prime class instances are referenced counted.
// The initial reference count is 0 after the instance is created.
// When the reference count is smaller or equal to 0 in unref(),
// the instance will be deleted automatically. Increasing reference
// count here for all member variables will guarantee that they will
// not be deleted until myApp is deleted. // get a pointer to the second tank so we can enable it's position
// strategy later on
m_tank = vpObject::find("tank 2");
m_tank->ref(); // add a subscriber to the left mouse button so we know when it's been
// pressed (i.e. when the user has started the moving the first tank).
// Note here that the motion model doesn't create the default mouse
// input device until the first update so we'll need to specify our
// own input device for it to use instead.
vpMotionDrive *motion = *vpMotionDrive::begin();
vpInputMouse *mouse = new vpInputMouse();
mouse->setWindow(*vpWindow::begin());
motion->setInput(mouse);
vpInputSourceBoolean *leftMouseButton = mouse->getSourceBoolean(
vpInputMouse::SOURCE_BOOLEAN_BUTTON_LEFT);
leftMouseButton->addSubscriber(
vpInputSourceBoolean::EVENT_FALLING_EDGE, this); return vsgu::SUCCESS; } /**
* notification that the left mouse button has been pressed
*/
virtual void notify(vpInputSourceBoolean::Event event,
vpInputSourceBoolean *source)
{ // set a timer to enable the position strategy on the second tank in
// 2 seconds
vpTimer::instance()->addSubscriber(this, 2.0f); // delete the subscriber so we don't get called again. Note here that
// since we're trying to remove the subscriber within the notification
// function itself that we need to due a delayed removal (as indicated
// by passing 'false' as the last argument) in order to be
// multithread safe.
source->removeSubscriber(event, this, false); } /**
* notification that the timer has expired
*/
virtual void notify(vpTimer *)
{
// enable the position strategy for the second tank
m_tank->setStrategyEnable(true);
}private: // the input source for the left mouse button so we can uninstall our
// subscriber
vpInputSourceBoolean *m_leftMouseButton;
// our tank object
vpObject *m_tank;};int main(int argc, char *argv[])
{ // initialize vega prime
vp::initialize(argc, argv); // create my app instance
myApp *app = new myApp; // load the acf file
if (argc <= 1)
app->define("vp_timer.acf");
else app->define(argv[1]); // configure my app
app->configure(); // execute the main runtime loop
app->run(); // delete my app instance
app->unref(); // shutdown vega prime
vp::shutdown(); return 0;}
这是VP的一个示例代码,我才学VC可能不太了解.原来是用CB的.我想请教一下关于程序执行的问题,notify函数是如何被调用的,也没有键盘响应的消息,对这个问题,我好象没有弄明白,哪位高手指点小弟一下?万分感谢!!
#include
#include
#include
#include
#include
#include // track memory leaks
vuAllocTracer m_allocTracer;// we need to derive our application class from the vpInputSourceBoolean and
// vpTimer subscriber classes so we can be notified of mouse button presses
// and timer expiration events
class myApp : public vpApp, public vpInputSourceBoolean::Subscriber,
public vpTimer::Subscriber
{public: /**
* Constructor
*/
myApp()
{} /**
* Destructor
*/
~myApp()
{
// unreference member variables which cache Vega Prime class instances
m_tank->unref();
}
/**
* Configure my app
*/
int configure() { // pre-configuration // configure vega prime system first
vpApp::configure(); // post-configuration // Increase the reference count by one for all member variables which
// cache the Vega Prime class instances.
//
// All VSG/Vega Prime class instances are referenced counted.
// The initial reference count is 0 after the instance is created.
// When the reference count is smaller or equal to 0 in unref(),
// the instance will be deleted automatically. Increasing reference
// count here for all member variables will guarantee that they will
// not be deleted until myApp is deleted. // get a pointer to the second tank so we can enable it's position
// strategy later on
m_tank = vpObject::find("tank 2");
m_tank->ref(); // add a subscriber to the left mouse button so we know when it's been
// pressed (i.e. when the user has started the moving the first tank).
// Note here that the motion model doesn't create the default mouse
// input device until the first update so we'll need to specify our
// own input device for it to use instead.
vpMotionDrive *motion = *vpMotionDrive::begin();
vpInputMouse *mouse = new vpInputMouse();
mouse->setWindow(*vpWindow::begin());
motion->setInput(mouse);
vpInputSourceBoolean *leftMouseButton = mouse->getSourceBoolean(
vpInputMouse::SOURCE_BOOLEAN_BUTTON_LEFT);
leftMouseButton->addSubscriber(
vpInputSourceBoolean::EVENT_FALLING_EDGE, this); return vsgu::SUCCESS; } /**
* notification that the left mouse button has been pressed
*/
virtual void notify(vpInputSourceBoolean::Event event,
vpInputSourceBoolean *source)
{ // set a timer to enable the position strategy on the second tank in
// 2 seconds
vpTimer::instance()->addSubscriber(this, 2.0f); // delete the subscriber so we don't get called again. Note here that
// since we're trying to remove the subscriber within the notification
// function itself that we need to due a delayed removal (as indicated
// by passing 'false' as the last argument) in order to be
// multithread safe.
source->removeSubscriber(event, this, false); } /**
* notification that the timer has expired
*/
virtual void notify(vpTimer *)
{
// enable the position strategy for the second tank
m_tank->setStrategyEnable(true);
}private: // the input source for the left mouse button so we can uninstall our
// subscriber
vpInputSourceBoolean *m_leftMouseButton;
// our tank object
vpObject *m_tank;};int main(int argc, char *argv[])
{ // initialize vega prime
vp::initialize(argc, argv); // create my app instance
myApp *app = new myApp; // load the acf file
if (argc <= 1)
app->define("vp_timer.acf");
else app->define(argv[1]); // configure my app
app->configure(); // execute the main runtime loop
app->run(); // delete my app instance
app->unref(); // shutdown vega prime
vp::shutdown(); return 0;}
这是VP的一个示例代码,我才学VC可能不太了解.原来是用CB的.我想请教一下关于程序执行的问题,notify函数是如何被调用的,也没有键盘响应的消息,对这个问题,我好象没有弄明白,哪位高手指点小弟一下?万分感谢!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货