Permalink
Browse files

Добавлен примитив Plane

  • Loading branch information...
1 parent 0f3b8c1 commit 9698e9ec66fcb13c5b33035c1f240f124f6b4fac @flexoid committed Sep 15, 2011
Showing with 63 additions and 2 deletions.
  1. +4 −1 src/CMakeLists.txt
  2. +4 −1 src/main.cpp
  3. +36 −0 src/primitives/plane.cpp
  4. +19 −0 src/primitives/plane.h
View
@@ -38,7 +38,10 @@ set (SOURCES
primitives/primitive.h
primitives/sphere.cpp
- primitives/sphere.h)
+ primitives/sphere.h
+
+ primitives/plane.cpp
+ primitives/plane.h)
set (EXECUTABLE_OUTPUT_PATH ../bin)
View
@@ -9,6 +9,7 @@
#include "engine.h"
#include "scene.h"
#include "primitives/sphere.h"
+#include "primitives/plane.h"
#define HEIGHT 700
#define WIDTH 700
@@ -38,15 +39,17 @@ int main()
*/
Material mat1(0.4f, 0.4f, 0.0f, 0.2f, 1.0f);
Material mat2(0.0f, 0.1f, 0.0f, 0.6f, 0.3f);
+ Material mat3(0.0f, 0.1f, 1.0f, 0.0f, 0.0f);
Scene* scene = new Scene(ColorRGB::Null());
scene->AddPrimitive(new Sphere(Vector3(0.0f,1.0f,0.0f),1.0f,ColorRGB(100,100, 0),mat1));
scene->AddPrimitive(new Sphere(Vector3(0.0f,-1.0f,0.0f),1.0f,ColorRGB( 0,100,100),mat1));
scene->AddPrimitive(new Sphere(Vector3(3.0f,0.0f,0.0f),0.5f,ColorRGB( 50,230, 50),mat2));
scene->AddLight(new Light(Vector3(2.0f,0.0f,0.0f),7.5f));
- Camera* camera = new Camera(Vector3(5.0f,0.0f,0.0f),Vector3::Null(),1.0f,1.0f);
+ Camera* camera = new Camera(Vector3(10.0f,0.0f,0.0f),Vector3::Null(),1.0f,1.0f);
scene->AddCamera(camera);
+ scene->AddPrimitive(new Plane(Vector3(0.0f, 0.0, -1.0), Vector3(0.0f, 0.0f, 1.0f), ColorRGB( 90,60, 50), mat3));
Screen* screen = new Screen(camera, scene, HEIGHT, WIDTH);
View
@@ -0,0 +1,36 @@
+#include "plane.h"
+//#include "math.h"
+#include "../math_c.h"
+
+Plane::Plane(Vector3 point, Vector3 norm, ColorRGB color, Material material)
+ : point(point), norm(norm.Norm())
+{
+ this->color = color;
+ this->material = material;
+}
+
+Vector3 Plane::Norm(Vector3 point)
+{
+ return norm;
+}
+
+Vector3 Plane::Trace(Ray ray)
+{
+ float sn = ray.dir.DotProduct(norm);
+
+ if (sn == 0)
+ return Vector3::Null();
+
+ float dotPointNorm = point.DotProduct(norm);
+ float t = (dotPointNorm - ray.from.DotProduct(norm)) / sn;
+
+ if (t < EPS)
+ return Vector3::Null();
+
+ return ray.from + ray.dir * t;
+}
+
+ColorRGB Plane::Color()
+{
+ return color;
+}
View
@@ -0,0 +1,19 @@
+#ifndef PLANE_H
+#define PLANE_H
+
+#include "primitive.h"
+
+class Plane : public Primitive
+{
+public:
+ Plane(Vector3 point, Vector3 norm, ColorRGB color, Material material);
+
+ virtual Vector3 Norm(Vector3 point);
+ virtual Vector3 Trace(Ray);
+ virtual ColorRGB Color();
+private:
+ Vector3 point;
+ Vector3 norm;
+};
+
+#endif // PLANE_H

1 comment on commit 9698e9e

Owner

flexoid commented on 9698e9e Sep 16, 2011

Issue #3

Please sign in to comment.