Beispiel #1
0
bool Mode::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex) {
	_x = (int)(x + getX() + _container->getX() + app->_stage->getX());
	_y = (int)(y + getY() + _container->getY() + app->_stage->getY());
	if(isSelecting()) _touchPt.set(evt, _x, _y, true);
	else _touchPt.set(evt, _x, _y, _plane);
	_camera->pickRay(app->getViewport(), _x, _y, &_ray);
	switch(evt) {
		case Touch::TOUCH_PRESS: {
			cout << "mode ray: " << app->pv(_ray.getOrigin()) << " => " << app->pv(_ray.getDirection()) << endl;
			MyNode *node = getTouchNode();
			if(node) node->updateTransform();
			if(isSelecting()) {
				Vector3 point = getTouchPoint();
				if(node) node->setBase();
				setSelectedNode(node, point);
				if(node) cout << "selected: " << node->getId() << " at " << app->pv(point) << endl;
			} else {
				_cameraBase->getNode()->set(*_camera->getNode());
				_viewportBase = app->getViewport();
				app->copyCameraState(app->_cameraState, _cameraStateBase);
				cout << "touched: camera at " << app->pcam(_cameraStateBase) << endl;
			}
			break;
		} case Touch::TOUCH_MOVE: {
			if(isTouching() && app->_navMode >= 0) {
				placeCamera();
			}
			break;
		} case Touch::TOUCH_RELEASE: {
			break;
		}
	}
	return true;
}
Beispiel #2
0
static void stepCamera(float distance)
{
	cameraPosition[0] += distance * cos(2.0 * M_PI * (cameraAngle + 90) / 360.0);
	cameraPosition[2] += distance * sin(2.0 * M_PI * (cameraAngle + 90) / 360.0);
	
	placeCamera();
}
Beispiel #3
0
static void translateCamera(float distance)
{
	cameraPosition[0] += distance * cameraOrientation[0];
	cameraPosition[1] += distance * cameraOrientation[1];
	cameraPosition[2] += distance * cameraOrientation[2];
	
	placeCamera();
}
Beispiel #4
0
static void rotateCamera(float angle)
{
	cameraAngle += angle;
	
	cameraOrientation[0] = cos(2.0 * M_PI * cameraAngle / 360.0);
	cameraOrientation[2] = sin(2.0 * M_PI * cameraAngle / 360.0);
	
	placeCamera();
}
Beispiel #5
0
void init(void) {
  glClearColor(0.0, 0.0, 0.0, 0.0);
  glShadeModel(GL_SMOOTH);
  glEnable(GL_DEPTH_TEST);
  initLighting();	
  initTextures();

  /* initialize projection matrix */
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glFrustum(-.5,.5,-.5,.5,1.0,35.0);

  /* initialize viewing transform matrix (= camera position) and save */
  placeCamera();

}
Beispiel #6
0
void viewport::place(){
  glViewport(vpWOffset, (height - vpHeight) - vpHOffset, vpWidth, vpHeight);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  gluPerspective(fov, aspect, znear, zfar);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  placeCamera();

  drawBackground();

  if(wireframe_f){
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  }
  else
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

  if(light_f)
    glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
}
Beispiel #7
0
static void display(void)
{
	placeCamera();
	drawHouse();
	glutSwapBuffers();
}