`
jacky-zhang
  • 浏览: 315974 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

opengl:rotate any angle

 
阅读更多
废话不多说了,直接贴代码
/**
	 * // camera target:We are looking toward the distance
	 * @param tx, the camera target x
	 * @param ty, the camera target y
	 * @param tz, the camera target z
	 * // Set our up vector. This is where our head would be pointing were we holding the camera.for example, (0,1,0),we'll toward the up position to rotate
	 * @param upX
	 * @param upY
	 * @param upZ
	 * @param angle
	 * @return
	 */
	private float[] roateAnyAngle(float tx, float ty, float tz, float upX, float upY, float upZ, float angle){
		float[] nt = new float[3];
		double x = tx;
		double y = ty;
		double z = tz;
		double u = upX;
		double v = upY;
		double w = upZ;
		
		double ux = u * x;
		double uy = u * y;
		double uz = u * z;
		double vx = v * x;
		double vy = v * y;
		double vz = v * z;
		double wx = w * x;
		double wy = w * y;
		double wz = w * z;
		double sa = Math.sin(angle);
		double ca = Math.cos(angle);
		nt[0] = (float) (u * (ux + vy + wz)
				+ (x * (v * v + w * w) - u * (vy + wz)) * ca + (-wy + vz) * sa);
		nt[1] = (float) (v * (ux + vy + wz)
				+ (y * (u * u + w * w) - v * (ux + wz)) * ca + (wx - uz) * sa);
		nt[2] = (float) (w * (ux + vy + wz)
				+ (z * (u * u + v * v) - w * (ux + vy)) * ca + (-vx + uy) * sa);
		return nt;
	}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics