-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shape.cs
75 lines (58 loc) · 3.15 KB
/
Shape.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace randomImage
{
public class Shape
{
public Vector position;
public Material material;
public Matrix4By4 transformMatrix = new Matrix4By4(new Matrix(), new Vector());
public Matrix4By4 inverseTransformMatrix = new Matrix4By4(new Matrix(), new Vector());
public Shape(Vector position, Material material)
{
this.position = position;
this.material = material;
}
public virtual double DoesIntersect(Vector origin, Vector direction)
{
return -1;
}
public virtual Vector NormalAtPoint(Vector point)
{
return new Vector(0, 0, 0);
}
/*
// to find the reflected ray after reflection
public virtual Vector ReflectedRay(Vector direction, Vector normal) {
Vector reflectionRay = direction - 2 * (normal * direction) * normal;
return reflectionRay;
}*/
public void AddTranslationToTranformationMatrix(Vector translate) {
transformMatrix = new Matrix4By4(new Matrix(), translate) * transformMatrix;
inverseTransformMatrix *= new Matrix4By4(new Matrix(), (-1) * translate);
}
public void AddScaleToTransformationMatrix(Vector scale) {
transformMatrix = new Matrix4By4(new Matrix(new Vector(scale.x,0,0), new Vector(0,scale.y,0), new Vector(0,0,scale.z)), new Vector());
inverseTransformMatrix *= new Matrix4By4(new Matrix(new Vector((1/scale.x),0,0), new Vector(0,(1/scale.y),0), new Vector(0,0,(1/scale.z))), new Vector());
}
public void AddRotationThroughXAxisToTransformationMatrix(double rotationAngleThroughXAxis) {
transformMatrix = Matrix4By4.XRotation(rotationAngleThroughXAxis) * transformMatrix;
inverseTransformMatrix *= Matrix4By4.XRotation(-rotationAngleThroughXAxis);
}
public void AddRotationThroughYAxisToTransformationMatrix(double rotationAngleThroughYAxis) {
transformMatrix = Matrix4By4.XRotation(rotationAngleThroughYAxis) * transformMatrix;
inverseTransformMatrix *= Matrix4By4.YRotation(-rotationAngleThroughYAxis);
}
public void AddRotationThroughZAxisToTransformationMatrix(double rotationAngleThroughZAxis) {
transformMatrix = Matrix4By4.ZRotation(rotationAngleThroughZAxis) * transformMatrix;
inverseTransformMatrix *= Matrix4By4.ZRotation(-rotationAngleThroughZAxis);
}
public void AddRotationThroughAllAxisToTransformationMatrix(double rotationAngleThroughXAxis, double rotationAngleThroughYAxis, double rotaionAngleThroughZAxis) {
transformMatrix = Matrix4By4.ZRotation(rotaionAngleThroughZAxis) * Matrix4By4.YRotation(rotationAngleThroughYAxis) * Matrix4By4.XRotation(rotationAngleThroughXAxis) * transformMatrix;
inverseTransformMatrix *= Matrix4By4.XRotation(-rotationAngleThroughXAxis) * Matrix4By4.YRotation(-rotationAngleThroughYAxis) * Matrix4By4.ZRotation(-rotaionAngleThroughZAxis);
}
}
}