// Fatory Methods public static Matrix3 rotation(Vector3 axis, final float angle) { if (angle == 0) return Identity; axis = axis.unit(); if (!axis.isFinite()) throw new RuntimeException(); final float c = GMath.cos(angle), s = GMath.sin(angle); return axis.mul(1 - c).mul(axis).add(Identity, c).add(axis.mul(s).tilda()); }
public static Quaternion makeRotation(Quaternion result, float theta, Vector axis) { float halfTheta = theta / 2; float sinHalfTheta = GMath.sin(halfTheta); result.w = GMath.cos(halfTheta); result.x = axis.getX() * sinHalfTheta; result.y = axis.getY() * sinHalfTheta; result.z = axis.getZ() * sinHalfTheta; return result; }
/** * Creates a new GStar centered at the origin with the indicated horizontal width. * * @param width The width of the star */ public GStar(double width) { double dx = width / 2; double dy = dx * GMath.tanDegrees(18); double edge = width / 2 - dy * GMath.tanDegrees(36); addVertex(-dx, -dy); int angle = 0; for (int i = 0; i < 5; i++) { addPolarEdge(edge, angle); addPolarEdge(edge, angle + 72); angle -= 72; } markAsComplete(); }
public float snap_cam_z_hud(float eye[], float center[], float up[]) { float lookAt[] = new float[16]; float eye2[] = new float[3]; for (int a = 0; a < 3; a++) { eye2[a] = eye[a]; } for (float ez = 1; ez < 100; ez += 0.05) { float cordx = mCanvasW; float cordy = 0; eye2[2] = ez; float win[] = new float[3]; GMath.lookAtf(lookAt, eye2, center, up); if (GLU.gluProject(cordx, cordy, 0.0f, lookAt, 0, mProjectionHud, 0, mViewport, 0, win, 0) == GL10.GL_TRUE && win[0] > 0 && win[0] < mViewport[2]) { mCameraEyeHud[0] = 0; mCameraEyeHud[1] = 0; mCameraEyeHud[2] = ez; saveLookAtHud(mCameraEyeHud, mCameraLookAtHud, mUpZHud); return ez; } } return 0; }
public void screen2spaceVecHud(float x, float y, float[] vec) { float c[] = new float[3]; y = mViewport[3] - y; GMath.unProject(x, y, 1.0f, mLookAtHud, 0, mProjectionHud, 0, mViewport, 0, c, 0); vec[0] = c[0] - this.mCameraEyeHud[0]; vec[1] = c[1] - this.mCameraEyeHud[1]; vec[2] = c[2] - this.mCameraEyeHud[2]; }
/** converts to quaternion */ public Quaternion quaternion() { if (a.x + b.y + c.z >= 0) { final float s = GMath.sqrt(1 + a.x + b.y + c.z) * 2; return new Quaternion(s / 4, (c.y - b.z) / s, (a.z - c.x) / s, (b.x - a.y) / s); } if (a.x >= b.y && a.x >= c.z) { final float s = GMath.sqrt(1 + a.x - b.y - c.z) * 2; return new Quaternion((c.y - b.z) / s, s / 4, (a.y + b.x) / s, (c.x + a.z) / s); } if (b.y >= c.z) { final float s = GMath.sqrt(1 - a.x + b.y - c.z) * 2; return new Quaternion((a.z - c.x) / s, (a.y + b.x) / s, s / 4, (b.z + c.y) / s); } final float s = GMath.sqrt(1 - a.x - b.y + c.z) * 2; return new Quaternion((b.x - a.y) / s, (c.x + a.z) / s, (b.z + c.y) / s, s / 4); }
public void screen2space(float x, float y, float[] spacecoords) { float c[] = new float[3]; float f[] = new float[3]; y = mViewport[3] - y; GMath.unProject(x, y, 1.0f, mLookAt, 0, mProjection, 0, mViewport, 0, f, 0); GMath.unProject(x, y, 0.0f, mLookAt, 0, mProjection, 0, mViewport, 0, c, 0); f[0] -= c[0]; f[1] -= c[1]; f[2] -= c[2]; float rayLength = (float) Math.sqrt(c[0] * c[0] + c[1] * c[1] + c[2] * c[2]); // normalize f[0] /= rayLength; f[1] /= rayLength; f[2] /= rayLength; float dot1, dot2; float pointInPlaneX = 0; float pointInPlaneY = 0; float pointInPlaneZ = 0; float planeNormalX = 0; float planeNormalY = 0; float planeNormalZ = -1; pointInPlaneX -= c[0]; pointInPlaneY -= c[1]; pointInPlaneZ -= c[2]; dot1 = (planeNormalX * pointInPlaneX) + (planeNormalY * pointInPlaneY) + (planeNormalZ * pointInPlaneZ); dot2 = (planeNormalX * f[0]) + (planeNormalY * f[1]) + (planeNormalZ * f[2]); float t = dot1 / dot2; f[0] *= t; f[1] *= t; spacecoords[0] = f[0] + c[0]; spacecoords[1] = f[1] + c[1]; }
public float normalizeIfNot() { float magSq = magnitudeSquared(); if (magSq != 1) { float mag = GMath.sqrt(magSq); this.w = w / mag; this.x = x / mag; this.y = y / mag; this.z = z / mag; return mag; } else { return 1; } }
public void saveLookAtHud(float[] eye, float[] center, float[] up) { for (int a = 0; a < 16; a++) { mLookAtHud[a] = 0; } GMath.lookAtf(mLookAtHud, eye, center, up); }
public float magnitude() { return GMath.sqrt(magnitudeSquared()); }