lonestar

0x10c-inspired space game based on the DCPU-16
git clone git://squid-tech.com/lonestar.git
Log | Files | Refs | README

commit ac2d80d7e08dbd86e58ee68468b7b136504e84d5
parent c7a800c3c469f469b8f25d5f8cc505abb3a8a5e7
Author: Josh Moore <jxm5210@rit.edu>
Date:   Mon, 25 Nov 2019 20:38:36 -0500

Render underside of floor/ceiling

Diffstat:
Msrc/LoneStar/Assets/Scripts/ShipLoader.cs | 38+++++++++++++++++++++++---------------
1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/src/LoneStar/Assets/Scripts/ShipLoader.cs b/src/LoneStar/Assets/Scripts/ShipLoader.cs @@ -24,11 +24,11 @@ public class ShipLoader this.shipname = name; } - // calculate all of the triangles for a mesh - //\TODO draw triangles for the underside as well + // calculate all of the triangles for the floor mesh + // returns the top AND bottom triangles int[] computeTriangles(Vector3[] points) { - int[] triangles = new int[points.Length * 6]; + int[] triangles = new int[points.Length * 6 * 2]; int ti = 0; for (int y = 0; y < 24; y++) @@ -50,6 +50,10 @@ public class ShipLoader triangles[ti] = a; triangles[ti + 1] = d; triangles[ti + 2] = b; + //bottom + triangles[triangles.Length/2 + ti] = a + points.Length/2; + triangles[triangles.Length / 2 + ti + 1] = b + points.Length/2; + triangles[triangles.Length / 2 + ti + 2] = d + points.Length/2; ti += 3; } else if (c > -1 && d > -1) @@ -58,6 +62,10 @@ public class ShipLoader triangles[ti] = a; triangles[ti + 1] = d; triangles[ti + 2] = c; + //bottom + triangles[triangles.Length/2 + ti] = a + points.Length / 2; + triangles[triangles.Length / 2 + ti + 1] = c + points.Length / 2; + triangles[triangles.Length / 2 + ti + 2] = d + points.Length / 2; ti += 3; } else if (b > -1 && c > -1) @@ -66,6 +74,10 @@ public class ShipLoader triangles[ti] = a; triangles[ti + 1] = c; triangles[ti + 2] = b; + // bottom + triangles[triangles.Length / 2 + ti] = a + points.Length / 2; + triangles[triangles.Length / 2 + ti + 1] = b + points.Length / 2; + triangles[triangles.Length / 2 + ti + 2] = c + points.Length / 2; ti += 3; } } @@ -76,6 +88,10 @@ public class ShipLoader triangles[ti] = b; triangles[ti + 1] = d; triangles[ti + 2] = c; + // bottom + triangles[triangles.Length / 2 + ti] = b + points.Length / 2; + triangles[triangles.Length / 2 + ti + 1] = c + points.Length / 2; + triangles[triangles.Length / 2 + ti + 2] = d + points.Length / 2; ti += 3; } } @@ -193,19 +209,11 @@ public class ShipLoader // copy generated mesh grid to Vector3[] array // this is our mesh vertices - Vector3[] gridPoints = new Vector3[generatedVerts.Count]; - for (int i = 0; i < gridPoints.Length; i++) + Vector3[] gridPoints = new Vector3[generatedVerts.Count * 2]; + for (int i = 0; i < gridPoints.Length/2; i++) { - gridPoints[i] = generatedVerts[i % generatedVerts.Count]; - - GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); - sphere.transform.parent = shipObject.transform; - sphere.transform.localScale = new Vector3(0.5f, 0.25f, 0.25f); - sphere.transform.position = gridPoints[i] + new Vector3(0, -SHIP_SCALE / 2, 0.1f); - - Light light = sphere.AddComponent<Light>(); - light.type = LightType.Point; - light.color = Color.red; + gridPoints[i] = generatedVerts[i]; + gridPoints[i + gridPoints.Length / 2] = generatedVerts[i]; } // calculate mesh triangles