-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSphere.cs
More file actions
71 lines (60 loc) · 2.38 KB
/
Copy pathSphere.cs
File metadata and controls
71 lines (60 loc) · 2.38 KB
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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Net.WebSockets;
using System.Numerics;
using System.Text;
using Template;
namespace INFOGRTemplate
{
internal class Sphere : Primitive
{
public float radius;
public Sphere(Vector3 _position, float _radius, Color3 _color, Materials _material, bool _checkers) : base(_color, _position, PrimitiveTypes.Sphere, _material, _checkers)
{
this.position = _position;
this.radius = _radius;
}
//calculates the intersection point closest the place the ray was fired from
public Vector3 ClosestIntersectPoint(Ray ray)
{
Intersection intersection = Intersect(ray);
if (intersection.intersectCount == 1)
{
return intersection.intersectionPoints[0];
}
else if (intersection.intersectCount == 2)
{
float Distance1 = Vector3.Distance(intersection.intersectionPoints[0], ray.startPosition);
float Distance2 = Vector3.Distance(intersection.intersectionPoints[1], ray.startPosition);
if (Distance1 <= Distance2) //return the intersection point where the distance to the starting point of the ray is the smallest
return intersection.intersectionPoints[0];
else
return intersection.intersectionPoints[1];
}
else
{
return Vector3.Zero;
}
}
public override Color3 checkerBoards(Vector3 hitPoint, Vector3 normalVector, float distance)
{
float scale = 10f;
//calculate the radians
float U_Rad = MathF.Acos(normalVector.Z);
float V_Rad = MathF.Asin(normalVector.Y / MathF.Sin(U_Rad));
//make the radians into angles
float U_Angle = U_Rad * (180 / MathF.PI);
float V_Angle = V_Rad * (180 / MathF.PI);
//place them onto the grid
int U = (int)Math.Floor(U_Angle / scale);
int V = (int)Math.Floor(V_Angle / scale);
// if the Tile is even, color it black (- the given color).
bool Tile = ((U + V) % 2) == 0;
if (Tile)
return new Color3(1f, 1f, 1f) - color;
else
return color;
}
}
}