示例#1
0
		void flascc_event_mouseMoved(int x, int y) {
			GameContainer* container = ARK2D::getContainer();

			float thisx = (float) x;
			float thisy = (float) y;
			
			thisx -= container->getTranslateX();
			thisy -= container->getTranslateY();

			thisx /= container->getScale();
			thisy /= container->getScale();

			Input* i = ARK2D::getInput();
			ARK2D::getLog()->mouseMoved((int) thisx, (int) thisy, i->mouse_x, i->mouse_y);
			ARK2D::getGame()->mouseMoved((int) thisx, (int) thisy, i->mouse_x, i->mouse_y);
			i->mouse_x = (int) thisx;
			i->mouse_y = (int) thisy;
		}
示例#2
0
		void flascc_event_mouseUp(int button, int x, int y) {
			GameContainer* container = ARK2D::getContainer();

			float thisx = (float) x;
			float thisy = (float) y;
			thisx -= container->getTranslateX();
			thisy -= container->getTranslateY();

			thisx /= container->getScale();
			thisy /= container->getScale();

			unsigned int key = Input::MOUSE_BUTTON_LEFT;
			if (button == 0) {
				key = Input::MOUSE_BUTTON_LEFT;
			} else if (button == 1) {
				key = Input::MOUSE_BUTTON_RIGHT;
			}

			Input* i = ARK2D::getInput();
			i->mouse_x = (int) thisx;
			i->mouse_y = (int) thisy;
			i->releaseKey(key);
		}
示例#3
0
		void Camera::update() {
			SceneNode::update();

			if (viewportAutosize) {
				setViewport(0, 0, ARK2D::getContainer()->getDynamicWidth(), ARK2D::getContainer()->getDynamicHeight() );
			}

            direction = (lookAt - transform.position);
            direction.normalise();

			// need to set the matrix state. this is only important because lighting doesn't work if this isn't done

		    if (type == TYPE_ORTHO) {
		    	//our projection matrix will be an orthogonal one in this case
				//if the values are not floating point, this command does not work properly
				//need to multiply by aspect!!! (otherise will not scale properly)

				//projection = glm::ortho((scaleMaybe*-1) * float(viewportAspectRatio), scaleMaybe * float(viewportAspectRatio), scaleMaybe*-1, scaleMaybe, nearClip, farClip);
                projection.identity();
                projection.ortho2d((viewportOrtho3dScale*-1) * float(viewportAspectRatio), viewportOrtho3dScale * float(viewportAspectRatio), viewportOrtho3dScale*-1, viewportOrtho3dScale, nearClip, farClip);


					// http://www.opengl-tutorial.org/beginners-tutorials/tutorial-6-keyboard-and-mouse/
				float verticalAngle = camera_pitch;
				float horizontalAngle = camera_heading;
				direction.set(
					cos(verticalAngle) * sin(horizontalAngle),
					sin(verticalAngle),
					cos(verticalAngle) * cos(horizontalAngle)
				);

                lookAt = transform.position + direction;

		    } else if (type == TYPE_ORTHO_2D) {

				//projection = glm::ortho(float(viewportX), float(viewportWidth), float(viewportHeight), float(viewportY), float(nearClip), float(farClip));
                projection.identity();
                projection.ortho2d(float(viewportX), float(viewportWidth), float(viewportHeight), float(viewportY), float(nearClip), float(farClip));

                lookAt = transform.position + direction;

			} else if (type == TYPE_PERSPECTIVE) {
				//projection = glm::perspective(fieldOfView, viewportAspectRatio, nearClip, farClip);
                projection.identity();
                projection.perspective(fieldOfView, viewportAspectRatio, nearClip, farClip);
				//detmine axis for pitch rotation
                Vector3<float> axis = direction.cross(up);
				//compute quaternion for pitch based on the camera pitch angle
                Quaternion<float> pitch_quat = Quaternion<float>::angleAxis(MathUtil::toDegrees(camera_pitch), axis);
				//determine heading quaternion from the camera up vector and the heading angle
                Quaternion<float> heading_quat = Quaternion<float>::angleAxis(MathUtil::toDegrees(camera_heading), up);
				//add the two quaternions
				Quaternion<float> temp = pitch_quat.cross(heading_quat);
                temp.normalise();

                // http://www.opengl-tutorial.org/beginners-tutorials/tutorial-6-keyboard-and-mouse/
				float verticalAngle = camera_pitch;
				float horizontalAngle = camera_heading;
				direction.set(
					cos(verticalAngle) * sin(horizontalAngle),
					sin(verticalAngle),
					cos(verticalAngle) * cos(horizontalAngle)
				);

            	//set the look at to be infront of the camera
                lookAt = transform.position + direction;



			}






			// compute the MVP

			if (type == TYPE_ORTHO_2D) {

                //view.lookAt(transform.position.x, transform.position.y, transform.position.z, lookAt.x, lookAt.y, lookAt.z, up.x, up.y, up.z);

				//view = glm::translate(view, glm::vec3(container->getTranslateX(), container->getTranslateY(), 0.0f) );
				//view = glm::scale(view, glm::vec3(container->getScaleX(), container->getScaleY(), 0.0f) );
				GameContainer* container = ARK2D::getContainer();
				view.identity();
				view.lookAt(transform.position.x, transform.position.y, transform.position.z, lookAt.x, lookAt.y, lookAt.z, up.x, up.y, up.z);
                view.translate(container->getTranslateX(), container->getTranslateY(), 0.0f);
                // todo: rotate
                view.scale(container->getScaleX(), container->getScaleY(), 1.0f);

                model.identity(); // = glm::mat4(1.0f);

			} else if (type == TYPE_PERSPECTIVE || type == TYPE_ORTHO) {

				/*float scaleX = 1.0f / float(viewportWidth);
				float scaleY = 1.0f / float(viewportHeight);
				if (scaleX > scaleY) {
					scaleY = scaleX;
				} else {
					scaleX = scaleY;
				}
				view = glm::lookAt(position, lookAt, up);
				view = glm::scale(view, glm::vec3(scaleX, scaleY, 0.0) );
				view = glm::translate(view, glm::vec3(1280.0*-0.5, 720.0*-0.5, 0.0) );*/

//				view = glm::lookAt(position, lookAt, up);
                view.identity();
                view.lookAt(transform.position.x, transform.position.y, transform.position.z, lookAt.x, lookAt.y, lookAt.z, up.x, up.y, up.z);
//				model = glm::mat4(1.0f);
                model.identity();
			}

			//MVP = projection * view * model;

		}