📄 tornado.cpp
字号:
default:
// do what vpApp has defined
vpApp::onKeyInput(key, mod);
break;
}// end of switch(key)
} // end of overloaded onKeyInput method
/*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~
Method-- configure()
This method is defined in the vpApp class
Handles the configuration process, reading
ACF, initializing the kernel, pipeline, window
managing the relationships between the classes
~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*/
int configure()
{
// configure vega prime system first
vpApp::configure();
// find pointers to the necessary instances we need during
// the application.
// it is always a good idea to validate the pointers to avoid
// null pointer processing/errors/problems
// initialize instances
// if things go wrong.. get out!!!
if (initializeInstances() == vsgu::FAILURE)
return vsgu::FAILURE;
// Subscribe to the tornadoBumpIsector's hit event so we can figure
// out what was hit and react appropriately.
m_tornadoBumpIsector->addSubscriber(vpIsector::EVENT_HIT, &m_myAppSub);
// initialize the Subscriber class instances
// if things go wrong ... get out!!!
if (m_myAppSub.initializeSubscriberInstances() == vsgu::FAILURE)
return vsgu::FAILURE;
// set the flags
m_myAppSub.initializeSubscriberFlags();
// post-configuration
return vsgu::SUCCESS;
}// end of overloaded configuration method
/*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~
Method-- run ()
This method is defined in the vpApp class
Handles the frame rendering process
~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*/
void run()
{
while (beginFrame() != 0)
{
endFrame();
update ();
}
// to put everything back the way it was
unconfigure();
}// end of overloaded run method
/*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~
Method-- update ()
This method is defined in the vpApp class
Handles the updates
~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*/
void update()
{
// update vega prime system first
vpApp::update();
// check to see if the tornado is supposed to be in motion
if(m_tornadoFlag == true)
{
// check to see if we have reached the end of the
// tornado path file.
// if not, move the tornado
if (m_file->eof() == false)
moveTornado();
else
{
// if we have reached the end of the file turn off the
// move flag
// close the tornado.path file
m_tornadoFlag = FALSE;
m_file->close();
}
}// end of tornado processing
}// end of overloaded update method
private:
// private variables and members go here!
// variables for the left and right headlights
vpLight *m_leftHeadlight, *m_rightHeadlight;
// variables for the tornado pieces and parts
vpFxParticleSystem *m_tornadoTop;
vpFxParticleSystem *m_tornadoDebris;
vpTransform *m_tornadoTransform;
// variables to hold the tornado path values
double m_X,m_Y,m_Z;
// pointer for the cow tornado will 'pick up' during its
// cycle of destruction
vpObject *m_myCow;
// pointer for the tornadoBumpIsector
vpIsector *m_tornadoBumpIsector;
// pointer for the file containing the tornado path
vuFile *m_file;
// boolean flag verify if the tornado is in motion or not.
bool m_tornadoFlag;
//pointer to the actionObserver, you know the observer who
// goes where the action is.
vpObserver *m_actionObserver;
int m_currentTarget;
protected:
// pointer to the subscribers class
myAppSubscribers m_myAppSub;
};// end of myApp class definition
/*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~
method -- main()
enuff said
~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*/
int main(int argc, char *argv[])
{
// initialize vega prime
vp::initialize(argc, argv);
// initialize addition modules here
//vpModule::initializeModule(modulename);
// create a vpApp instance but use the class
// you just created
myApp *app = new myApp;
// load acf
// use the hardcoded default ACF value or
// use the 2nd argument from the command line
if (argc <= 1)
app->define("..\\completed_acf\\tornado.acf");
else
app->define(argv[1]);
// configure my app
// if the application configuration fails for some reason
// shut down the application.
// The penalty for a failed configuration is user defined
if (app->configure() == vsgu::FAILURE)
{
vuNotify::print(vuNotify::LEVEL_WARN, NULL, "configuration failed! Exiting NOW!");
app->unref();
vp::shutdown();
}
// runtime loop
app->run();
// unref my app instance
app->unref();
// shutdown vega prime
vp::shutdown();
return 0;
}
/*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~
Method-- update ()
This method is defined in the vpApp class
Handles the updates
~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*/
int myApp::initializeInstances()
{
// find and validate a pointer to the left headlight instance
m_leftHeadlight = vpLight::find("leftHeadlight");
if (m_leftHeadlight == NULL)
{
vuNotify::print(vuNotify::LEVEL_WARN, NULL, "leftHeadlight not found");
return vsgu::FAILURE;
}
// find and validate a pointer to the right headlight instance
m_rightHeadlight = vpLight::find("rightHeadlight");
if (m_rightHeadlight == NULL)
{
vuNotify::print(vuNotify::LEVEL_WARN, NULL, "rightHeadlight not found");
return vsgu::FAILURE;
}
// find and validate a pointer to the actionObserver instance
m_actionObserver = vpObserver::find("houseObserver");
if (m_actionObserver == NULL)
{
vuNotify::print(vuNotify::LEVEL_WARN, NULL, "houseObserver not found");
return vsgu::FAILURE;
}
// find and validate a pointer to the tornadoDebris instance
m_tornadoDebris = vpFxParticleSystem::find ("tornadoDebris");
if (m_tornadoDebris == NULL)
{
vuNotify::print(vuNotify::LEVEL_WARN, NULL, "tornadoDebris not found");
return vsgu::FAILURE;
}
// find and validate a pointer to the tornadoTransform instance
m_tornadoTransform = vpTransform::find("tornadoTransform");
if (m_tornadoTransform == NULL)
{
vuNotify::print(vuNotify::LEVEL_WARN, NULL, "tornadoTransform not found");
return vsgu::FAILURE;
}
// find and validate a pointer to the tornadoBumpIsector instance
m_tornadoBumpIsector = vpIsector::find("tornadoBumpIsector");
if (m_tornadoBumpIsector == NULL)
{
vuNotify::print(vuNotify::LEVEL_WARN, NULL, "tornadoBumpIsector not found");
return vsgu::FAILURE;
}
return vsgu::SUCCESS;
}
/*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~
method -- processHeadlights
turn the headlights on and off
with a keystroke.
~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*/
void myApp::processHeadlights()
{
bool lightSetting;
if (m_leftHeadlight->getEnable() == true)
lightSetting = false;
else
lightSetting = true;
m_leftHeadlight->setRenderEnable(lightSetting);
m_leftHeadlight->setEnable(lightSetting);
m_rightHeadlight->setRenderEnable(lightSetting);
m_rightHeadlight->setEnable(lightSetting);
}
/*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~
method -- processTornado()
open up the tornado path file
turn on the tornadoFlag
~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*/
void myApp::processTornado()
{
// open the binary tornado.path file stored on the disk for reading only.
m_file->open("..\\DATA\\tornadoPath\\tornado.path", "rb");
// turn on the tornadoFlag so we can start moving the tornado
// on a per-frame basis in the update method.
m_tornadoFlag = true;
}
/*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~
method -- moveTornado()
read the XYZ from the binary file
move the tornado
rotate the debris cloud
This call is made during the update
~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*/
void myApp::moveTornado()
{
// read the XYZ coordinates from the tornado.path file
m_file->read(&m_X, sizeof(m_X));
m_file->read(&m_Y, sizeof(m_Y));
m_file->read(&m_Z, sizeof(m_Z));
// move the tornado transform; parent of the tornado top, funnel and debris
m_tornadoTransform->setTranslate(m_X,m_Y,m_Z);
// update the heading of the tornado debris so it appears to
// turn on it's own axis faster than the funnel
m_myAppSub.rotateDebris();
}
/*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~
method -- processObserverLookAt
set the lookAt target for the observer
to switch between looking at :
the house
the grainstorage
the tornado
~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*/
void myApp::processObserverLookAt()
{
// declare a few local variables
double X,Y,Z;
vpPositionable *newTarget;
vpPositionable *currentTarget;
vpPositionable * localFarmhouse, *localGrainStorage;
// retrieve a pointer to the current look at Target from the observer
currentTarget = (vpPositionable *)m_actionObserver->getLookAt();
localFarmhouse = (vpPositionable *) m_myAppSub.getFarmhouse();
localGrainStorage = (vpPositionable *) m_myAppSub.getGrainStorage();
// if the current target is the tornado transform
// set the new look at target to be the farmhouse
// modify the XYZ coordinates so it is somewhere near
// the farmhouse
if (currentTarget == m_tornadoTransform)
{
// action observer should now look at the farmhouse
X = 1950.00;
Y = 1200.00;
Z = 130.00;
newTarget = m_myAppSub.getFarmhouse();
}
// if the current target is the farmhouse
// set the new look at target to be the grainStorage Unit
// modify the XYZ coordinates so it is somewhere near
// the grainStorage unit
else if (currentTarget == localFarmhouse)
{
// action observer should look at the grain Storage
X = 2500.00;
Y = 2200.00;
Z = 120.00;
newTarget = m_myAppSub.getGrainStorage();
}
// if the current target is the grainStorage Unit
// set the new look at target to be the tornado Transform
// modify the XYZ coordinates so it is somewhere near
// the tornado Transform
else if (currentTarget == localGrainStorage)
{
// action observer should look at the tornado transform
X = 1000.00;
Y = 3000.00;
Z = 140.00;
newTarget = m_tornadoTransform;
}
// update the observer with the new lookat target and new position
m_actionObserver->setLookAt(newTarget);
m_actionObserver->setTranslate(X, Y, Z, false);
}
/*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~
method -- resetEverything()
restore the inital states
~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*~~*/
void myApp::resetEverything()
{
// tornado goes back to its initial position
// turn off the tornado flag
m_tornadoTransform->setTranslate(1460, 300, 12);
m_tornadoFlag = false;
m_myAppSub.resetSubscriberInstances();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -