A SERVICE OF

logo

198
Appendix B: Cosmo 3D Sample Application
int
frame(void*)
{
static int frame = 0;
const csEventArray &elist = csWindow::getCurrent()->getEvents();
for (int i=0; i<elist.getCount(); i++)
{
if (elist[i]->id == csEvent::KEY_PRESS) {
switch (elist[i]->key) {
case 'b':
doBorders = !doBorders;
csWindow::setWindowTitle(doBorders? "cube" : NULL);
break;
case 's':
csWindow::reshapeWindow(300, 300);
break;
case 'S':
csWindow::reshapeWindow(600, 600);
break;
case 27: // ESC
exit(1);
}
}
}
if(frame % 30 == 0 && doFlash)
ctx->pushOverrideAppearance(highlight);
else if(frame % 30 == 15 && doFlash)
ctx->popOverrideAppearance();
// clear the window
ctx->clear(csContext::COLOR_CLEAR | csContext::DEPTH_CLEAR);
// update cube rotations
bgTransform->setRotation(1.0f, 1.0f, 0.0f, CS_DEG2RAD(frame));
fgTransform->setRotation(0.5f, 0.1f, 1.0f, CS_DEG2RAD(frame));
// draw the scene
da->apply(root);