Browse Source

Add reverse matrix multiply functions

The *_i functions multiply the value by the matrix instead of the other
way around, then store the result.
jp9000 11 years ago
parent
commit
8d1d1ddd14
2 changed files with 62 additions and 0 deletions
  1. 51 0
      libobs/graphics/matrix4.c
  2. 11 0
      libobs/graphics/matrix4.h

+ 51 - 0
libobs/graphics/matrix4.c

@@ -178,6 +178,57 @@ void matrix4_scale(struct matrix4 *dst, const struct matrix4 *m,
 	matrix4_mul(dst, m, &temp);
 }
 
+void matrix4_translate3v_i(struct matrix4 *dst, const struct vec3 *v,
+		const struct matrix4 *m)
+{
+	struct matrix4 temp;
+	vec4_set(&temp.x, 1.0f, 0.0f, 0.0f, 0.0f);
+	vec4_set(&temp.y, 0.0f, 1.0f, 0.0f, 0.0f);
+	vec4_set(&temp.z, 0.0f, 0.0f, 1.0f, 0.0f);
+	vec4_from_vec3(&temp.t, v);
+
+	matrix4_mul(dst, &temp, m);
+}
+
+void matrix4_translate4v_i(struct matrix4 *dst, const struct vec4 *v,
+		const struct matrix4 *m)
+{
+	struct matrix4 temp;
+	vec4_set(&temp.x, 1.0f, 0.0f, 0.0f, 0.0f);
+	vec4_set(&temp.y, 0.0f, 1.0f, 0.0f, 0.0f);
+	vec4_set(&temp.z, 0.0f, 0.0f, 1.0f, 0.0f);
+	vec4_copy(&temp.t, v);
+
+	matrix4_mul(dst, &temp, m);
+}
+
+void matrix4_rotate_i(struct matrix4 *dst, const struct quat *q,
+		const struct matrix4 *m)
+{
+	struct matrix4 temp;
+	matrix4_from_quat(&temp, q);
+	matrix4_mul(dst, &temp, m);
+}
+
+void matrix4_rotate_aa_i(struct matrix4 *dst, const struct axisang *aa,
+		const struct matrix4 *m)
+{
+	struct matrix4 temp;
+	matrix4_from_axisang(&temp, aa);
+	matrix4_mul(dst, &temp, m);
+}
+
+void matrix4_scale_i(struct matrix4 *dst, const struct vec3 *v,
+		const struct matrix4 *m)
+{
+	struct matrix4 temp;
+	vec4_set(&temp.x, v->x, 0.0f, 0.0f, 0.0f);
+	vec4_set(&temp.y, 0.0f, v->y, 0.0f, 0.0f);
+	vec4_set(&temp.z, 0.0f, 0.0f, v->z, 0.0f);
+	vec4_set(&temp.t, 0.0f, 0.0f, 0.0f, 1.0f);
+	matrix4_mul(dst, &temp, m);
+}
+
 bool matrix4_inv(struct matrix4 *dst, const struct matrix4 *m)
 {
 	struct vec4 *dstv = (struct vec4 *)dst;

+ 11 - 0
libobs/graphics/matrix4.h

@@ -76,6 +76,17 @@ EXPORT void matrix4_scale(struct matrix4 *dst, const struct matrix4 *m,
 EXPORT bool matrix4_inv(struct matrix4 *dst, const struct matrix4 *m);
 EXPORT void matrix4_transpose(struct matrix4 *dst, const struct matrix4 *m);
 
+EXPORT void matrix4_translate3v_i(struct matrix4 *dst, const struct vec3 *v,
+		const struct matrix4 *m);
+EXPORT void matrix4_translate4v_i(struct matrix4 *dst, const struct vec4 *v,
+		const struct matrix4 *m);
+EXPORT void matrix4_rotate_i(struct matrix4 *dst, const struct quat *q,
+		const struct matrix4 *m);
+EXPORT void matrix4_rotate_aa_i(struct matrix4 *dst, const struct axisang *aa,
+		const struct matrix4 *m);
+EXPORT void matrix4_scale_i(struct matrix4 *dst, const struct vec3 *v,
+		const struct matrix4 *m);
+
 static inline void matrix4_translate3f(struct matrix4 *dst,
 		const struct matrix4 *m, float x, float y, float z)
 {