]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/clipplane.cpp
Rearrange soucre files into subdirectories
[libs/gl.git] / source / core / clipplane.cpp
diff --git a/source/core/clipplane.cpp b/source/core/clipplane.cpp
new file mode 100644 (file)
index 0000000..4adf2bf
--- /dev/null
@@ -0,0 +1,40 @@
+#include <msp/strings/format.h>
+#include "clipplane.h"
+#include "gl.h"
+#include "matrix.h"
+#include "misc.h"
+#include "programdata.h"
+
+namespace Msp {
+namespace GL {
+
+ClipPlane::ClipPlane():
+       eq(0, 0, 0, 1)
+{ }
+
+ClipPlane::ClipPlane(const Vector4 &e):
+       eq(e)
+{ }
+
+ClipPlane::ClipPlane(const Vector3 &p, const Vector3 &d):
+       eq(compose(d, -dot(p, d)))
+{ }
+
+void ClipPlane::set_equation(const Vector4 &e)
+{
+       eq = e;
+}
+
+void ClipPlane::set_plane(const Vector3 &p, const Vector3 &d)
+{
+       Vector3 nd = normalize(d);
+       set_equation(compose(nd, -dot(p, nd)));
+}
+
+void ClipPlane::update_shader_data(ProgramData &shdata, const Matrix &view_inverse, unsigned i) const
+{
+       shdata.uniform(format("clip_planes[%d].equation", i), eq*view_inverse);
+}
+
+} // namespace GL
+} // namespace Msp