This repository was archived by the owner on Aug 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPQSMod_FlattenAreaTangential.cs
More file actions
97 lines (82 loc) · 2.7 KB
/
PQSMod_FlattenAreaTangential.cs
File metadata and controls
97 lines (82 loc) · 2.7 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* libpqsmods - A standalone implementation of KSP's PQSMods
* Copyright (c) Thomas P. 2016
* Licensed under the terms of the MIT license
*/
using System;
using ProceduralQuadSphere.Unity;
using XnaGeometry;
namespace ProceduralQuadSphere
{
/// <summary>
/// A mod that makes a specific area on the planet completely flat (tangent version)
/// </summary>
/// <seealso cref="PQSMod" />
public class PQSMod_FlattenAreaTangential : PQSMod
{
/// <summary>
/// The outer radius of the flatten area
/// </summary>
public Double outerRadius;
/// <summary>
/// The inner radius of the flatten area
/// </summary>
public Double innerRadius;
/// <summary>
/// The position of the flatten area, relative to the planet
/// </summary>
public Vector3 position;
/// <summary>
/// The height of the surface
/// </summary>
public Double flattenTo;
/// <summary>
/// The smooth start of the flattening
/// </summary>
public Double smoothStart;
/// <summary>
/// The smooth end of the flattening
/// </summary>
public Double smoothEnd;
/// <summary>
/// The normalized position
/// </summary>
private Vector3 positionN;
/// <summary>
/// The inner angle for the flatten area
/// </summary>
private Double iAngle;
/// <summary>
/// The outer angle for the flatten area
/// </summary>
private Double oAngle;
/// <summary>
/// Sets up the defaults for the Mod
/// </summary>
public override void OnSetup()
{
positionN = Vector3.Normalize(position);
iAngle = Math.Atan(innerRadius / sphere.radius);
oAngle = Math.Atan(outerRadius / sphere.radius);
}
/// <summary>
/// Called when the parent sphere builds it's height
/// </summary>
public override void OnVertexBuildHeight(VertexBuildData data)
{
Double angle = Math.Acos(Vector3.Dot(data.directionFromCenter, positionN));
// Check for outer angle
if (angle >= oAngle)
return;
// Check for inner angle
if (angle < iAngle)
{
data.vertHeight = (sphere.radius + flattenTo) / Math.Cos(angle);
return;
}
// Flatten
Double delta = (angle - iAngle) / (oAngle - iAngle);
data.vertHeight = MathHelper.Hermite((sphere.radius + flattenTo) / Math.Cos(angle), smoothStart, data.vertHeight, smoothEnd, delta);
}
}
}