Skip to content

Commit

Permalink
Workarounds. Typos. IManipulateable.
Browse files Browse the repository at this point in the history
  • Loading branch information
zameran committed Mar 21, 2018
1 parent 70f270a commit 982817c
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 16 deletions.
26 changes: 21 additions & 5 deletions Assets/Project/SpaceEngine/Code/BodyRotator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 51,8 @@ public class BodyRotator : MonoBehaviour

public float RotationSpeed = 0.25f;

public Transform Rotator = null;

private void Start()
{
BodyCachedComponent.TryInit(this);
Expand All @@ -60,13 62,27 @@ private void Update()
{
var terrainNodes = BodyComponent.TerrainNodes;

for (var terrainNodeIndex = 0; terrainNodeIndex < terrainNodes.Count; terrainNodeIndex )
if (Rotator == null)
{
var terrainNode = terrainNodes[terrainNodeIndex];
for (var terrainNodeIndex = 0; terrainNodeIndex < terrainNodes.Count; terrainNodeIndex )
{
var terrainNode = terrainNodes[terrainNodeIndex];

// NOTE : Maybe full matrices recalculations needed via TerrainQuadRoot.CalculateMatrices(...)
terrainNode.transform.Rotate(RotationAxis * RotationSpeed * Time.deltaTime); // NOTE : Perform our transformation action...
terrainNode.TerrainQuadRoot.UpdateMatrices(); // NOTE : Recalculate and update critical variables, required for proper rendering.
}
}
else
{
Rotator.transform.Rotate(RotationAxis * RotationSpeed * Time.deltaTime); // NOTE : Perform our transformation action...

for (var terrainNodeIndex = 0; terrainNodeIndex < terrainNodes.Count; terrainNodeIndex )
{
var terrainNode = terrainNodes[terrainNodeIndex];

// NOTE : Maybe full matrices recalculations needed via TerrainQuadRoot.CalculateMatrices(...)
terrainNode.transform.Rotate(RotationAxis * RotationSpeed * Time.deltaTime); // NOTE : Perform our transformation action...
terrainNode.TerrainQuadRoot.UpdateMatrices(); // NOTE : Recalculate and update critical variables, required for proper rendering.
terrainNode.TerrainQuadRoot.UpdateMatrices(); // NOTE : Recalculate and update critical variables, required for proper rendering.
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 1,54 @@
#region License
// Procedural planet generator.
//
// Copyright (C) 2015-2018 Denis Ovchinnikov [zameran]
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holders nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION)HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE.
//
// Creation Date: 2018.03.21
// Creation Time: 12:19 PM
// Creator: zameran
#endregion

namespace SpaceEngine.Core.Patterns.Strategy
{
/// <summary>
/// This interface should be implemented in all things, that's gonna be moved, rotated or scaled externaly,
/// while using custom (special, unique) matrices or vectors, wich sould be updated, if transform is changed for proper rendering.
/// </summary>
public interface IManipulateable
{
/// <summary>
/// Updates necessary matrices for proper rendering.
/// </summary>
void UpdateMatrices();

/// <summary>
/// Updates necessary vectors for proper rendering.
/// </summary>
void UpdateVectors();
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions Assets/Project/SpaceEngine/Code/Core/Terrain/TerrainNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 214,7 @@ public override void InitNode()
LocalToWorld = Matrix4x4d.ToMatrix4x4d(transform.localToWorldMatrix) * FaceToLocal;
Deformation = new DeformationSpherical(celestialBody.Size);

TangentFrameToWorld = new Matrix3x3d(LocalToWorld.m[0, 0], LocalToWorld.m[0, 1], LocalToWorld.m[0, 2],
LocalToWorld.m[1, 0], LocalToWorld.m[1, 1], LocalToWorld.m[1, 2],
LocalToWorld.m[2, 0], LocalToWorld.m[2, 1], LocalToWorld.m[2, 2]);
TangentFrameToWorld = LocalToWorld.ToMatrix3x3d();

InitUniforms(TerrainMaterial);

Expand Down Expand Up @@ -245,9 243,7 @@ public override void UpdateNode()
// NOTE : Body shape dependent...
LocalToWorld = Matrix4x4d.ToMatrix4x4d(transform.localToWorldMatrix) * FaceToLocal;

TangentFrameToWorld = new Matrix3x3d(LocalToWorld.m[0, 0], LocalToWorld.m[0, 1], LocalToWorld.m[0, 2],
LocalToWorld.m[1, 0], LocalToWorld.m[1, 1], LocalToWorld.m[1, 2],
LocalToWorld.m[2, 0], LocalToWorld.m[2, 1], LocalToWorld.m[2, 2]);
TangentFrameToWorld = LocalToWorld.ToMatrix3x3d();

LocalToCamera = GodManager.Instance.View.WorldToCameraMatrix * LocalToWorld;
LocalToScreen = GodManager.Instance.View.CameraToScreenMatrix * LocalToCamera;
Expand Down
10 changes: 5 additions & 5 deletions Assets/Project/SpaceEngine/Code/Helpers/VectorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 105,12 @@ public static Vector4d Abs(this Vector4d v)

public static Vector3 RotatePointAroundPivot(this Vector3 point, Vector3 pivot, Vector3 angles)
{
var dir = point - pivot;

dir = Quaternion.Euler(angles) * dir;
point = dir pivot;
return RotatePointAroundPivot(point, pivot, Quaternion.Euler(angles));
}

return new Vector3(point.x, point.y, point.z);
public static Vector3 RotatePointAroundPivot(this Vector3 point, Vector3 pivot, Quaternion rotation)
{
return rotation * (point - pivot) pivot;
}

public static Vector3 NormalizeToRadius(this Vector3 v, float radius)
Expand Down

0 comments on commit 982817c

Please sign in to comment.