public Mat4f(Vec4f row1, Vec4f row2, Vec4f row3, Vec4f row4) { data = new Vec4f[4]; data[0] = row1; data[1] = row2; data[2] = row3; data[3] = row4; }
public Mat4f() { data = new Vec4f[4]; data[0] = new Vec4f(1.0f, 0.0f, 0.0f, 0.0f); data[1] = new Vec4f(0.0f, 1.0f, 0.0f, 0.0f); data[2] = new Vec4f(0.0f, 0.0f, 1.0f, 0.0f); data[3] = new Vec4f(0.0f, 0.0f, 0.0f, 1.0f); }
public static Mat4f ProjectionMatrix4(float angleOfView, float near, float far) { float scale = 1.0f / (float)(Math.Tan(angleOfView * 0.5f * (float)(Math.PI) / 180.0f)); Vec4f row1 = new Vec4f(scale, 0.0f, 0.0f, 0.0f); Vec4f row2 = new Vec4f(0.0f, scale, 0.0f, 0.0f); Vec4f row3 = new Vec4f(0.0f, 0.0f, -far / (far - near), -1.0f); Vec4f row4 = new Vec4f(0.0f, 0.0f, -far * near / (far - near), 0.0f); return(new Mat4f(row1, row2, row3, row4)); }
public static Mat4f RotationXMatrix(float angle) { float cosTheta = (float)Math.Cos(angle); float sinTheta = (float)Math.Sin(angle); Vec4f row1 = new Vec4f(1.0f, 0.0f, 0.0f, 0.0f); Vec4f row2 = new Vec4f(0.0f, cosTheta, -sinTheta, 0.0f); Vec4f row3 = new Vec4f(0.0f, sinTheta, cosTheta, 0.0f); Vec4f row4 = new Vec4f(0.0f, 0.0f, 0.0f, 1.0f); return(new Mat4f(row1, row2, row3, row4)); }
public static Vec4f operator *(Mat4f m1, Vec4f v1) { Vec4f outRes = new Vec4f(); outRes.x = v1.x * m1.data[0].x + v1.y * m1.data[1].x + v1.z * m1.data[2].x + m1.data[3].x; outRes.y = v1.x * m1.data[0].y + v1.y * m1.data[1].y + v1.z * m1.data[2].y + m1.data[3].y; outRes.z = v1.x * m1.data[0].z + v1.y * m1.data[1].z + v1.z * m1.data[2].z + m1.data[3].z; float w = v1.x * m1.data[0].w + v1.y * m1.data[1].w + v1.z * m1.data[2].w + m1.data[3].w; if (w != 1.0f) { outRes.x /= w; outRes.y /= w; outRes.z /= w; outRes.w /= w; } return(outRes); }
public static Mat4f operator *(Mat4f m1, Mat4f m2) { Vec4f ap1 = m1.data[0]; Vec4f ap2 = m1.data[1]; Vec4f ap3 = m1.data[2]; Vec4f ap4 = m1.data[3]; Vec4f bp1 = m2.data[0]; Vec4f bp2 = m2.data[1]; Vec4f bp3 = m2.data[2]; Vec4f bp4 = m2.data[3]; Vec4f cp1 = new Vec4f(); Vec4f cp2 = new Vec4f(); Vec4f cp3 = new Vec4f(); Vec4f cp4 = new Vec4f(); float a0, a1, a2, a3; a0 = ap1.x; a1 = ap1.y; a2 = ap1.z; a3 = ap1.w; cp1.x = a0 * bp1.x + a1 * bp2.x + a2 * bp3.x + a3 * bp4.x; cp1.y = a0 * bp1.y + a1 * bp2.y + a2 * bp3.y + a3 * bp4.y; cp1.z = a0 * bp1.z + a1 * bp2.z + a2 * bp3.z + a3 * bp4.z; cp1.w = a0 * bp1.w + a1 * bp2.w + a2 * bp3.w + a3 * bp4.w; a0 = ap2.x; a1 = ap2.y; a2 = ap2.z; a3 = ap2.w; cp2.x = a0 * bp1.x + a1 * bp2.x + a2 * bp3.x + a3 * bp4.x; cp2.y = a0 * bp1.y + a1 * bp2.y + a2 * bp3.y + a3 * bp4.y; cp2.z = a0 * bp1.z + a1 * bp2.z + a2 * bp3.z + a3 * bp4.z; cp2.w = a0 * bp1.w + a1 * bp2.w + a2 * bp3.w + a3 * bp4.w; a0 = ap3.x; a1 = ap3.y; a2 = ap3.z; a3 = ap3.w; cp3.x = a0 * bp1.x + a1 * bp2.x + a2 * bp3.x + a3 * bp4.x; cp3.y = a0 * bp1.y + a1 * bp2.y + a2 * bp3.y + a3 * bp4.y; cp3.z = a0 * bp1.z + a1 * bp2.z + a2 * bp3.z + a3 * bp4.z; cp3.w = a0 * bp1.w + a1 * bp2.w + a2 * bp3.w + a3 * bp4.w; a0 = ap4.x; a1 = ap4.y; a2 = ap4.z; a3 = ap4.w; cp4.x = a0 * bp1.x + a1 * bp2.x + a2 * bp3.x + a3 * bp4.x; cp4.y = a0 * bp1.y + a1 * bp2.y + a2 * bp3.y + a3 * bp4.y; cp4.z = a0 * bp1.z + a1 * bp2.z + a2 * bp3.z + a3 * bp4.z; cp4.w = a0 * bp1.w + a1 * bp2.w + a2 * bp3.w + a3 * bp4.w; return(new Mat4f(cp1, cp2, cp3, cp4)); }
public Vec3f(Vec4f other) { this.x = other.x; this.y = other.y; this.z = other.z; }