diff src/GlobalEyePoint.cpp @ 10:5727d511a13a

add src in Martial Project Xcode.
author tokumoritaichirou@nw0743.st.ie.u-ryukyu.ac.jp
date Wed, 03 Feb 2010 03:39:04 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/GlobalEyePoint.cpp	Wed Feb 03 03:39:04 2010 +0900
@@ -0,0 +1,69 @@
+/*
+ *  GlobalEyePoint.cpp
+ *  Martial
+ *
+ *  Created by ryoma on 10/01/28.
+ *  Copyright 2010 琉球大学. All rights reserved.
+ *
+ */
+
+#include "GlobalEyePoint.h"
+
+GlobalEyePoint::GlobalEyePoint(char* name) : EyePoint(name) {
+	Tman = new osgGA::TrackballManipulator();
+	offset = osg::Vec3(0,10,-2);
+	direction = osg::Vec3(0, 0, 90);
+}
+
+void GlobalEyePoint::setTarget(MovableObject* _target) {
+	targets.push_back(_target);
+}
+
+void GlobalEyePoint::frame() {
+	osg::Matrixd myCameraMatrix;
+	osg::Matrixd cameraRotation;
+	osg::Matrixd cameraTrans;
+	osg::Matrixd centerTrans;
+
+	std::list<MovableObject*>::iterator iter;
+
+	osg::Vec3 center = osg::Vec3(0,0,0), tmp;
+	float minX, maxX, minY, maxY, minZ, maxZ, length;
+	
+	for (iter = targets.begin(); iter != targets.end(); ++iter) {
+		tmp = (*iter)->getPos();
+
+		if (tmp.x() < minX) {
+			minX = tmp.x();
+		} else if (tmp.x() > maxX) {
+			maxX = tmp.x();
+		}
+
+		if (tmp.x() < minY) {
+			minY = tmp.y();
+		} else if (tmp.y() > maxY) {
+			maxY = tmp.y();
+		}
+
+		if (tmp.z() < minZ) {
+			minZ = tmp.z();
+		} else if (tmp.z() > maxZ) {
+			minZ = tmp.z();
+		}		
+		
+		center += tmp;
+	}
+
+	length = (osg::Vec3(maxX+minX, maxY+minY, maxZ+minZ).length()) * Martial::CONFIG::WINDOW_WIDTH / 500;
+
+	if (length < 10.0) length = 10.0;
+
+	center /= (float)targets.size();
+
+	position = osg::Vec3(center.x(), length, center.z())+offset;
+
+	cameraRotation.makeRotate(direction.z(), osg::Vec3(0,0,1));
+	myCameraMatrix.makeLookAt(position, center, osg::Vec3(0,0,1) * cameraRotation);
+
+	Tman->setByInverseMatrix(myCameraMatrix);
+}
\ No newline at end of file