Delete old files from tree
parent
3aadcbc8e4
commit
9ac0766ce4
@ -1,275 +0,0 @@
|
||||
#region --- License ---
|
||||
/* Licensed under the MIT/X11 license.
|
||||
* Copyright (c) 2006-2008 the OpenTK Team.
|
||||
* This notice may not be removed from any source distribution.
|
||||
* See license.txt for licensing details.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Windows.Forms;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
using SCJMapper_V2.Shapes;
|
||||
using SCJMapper_V2.TextureLoaders;
|
||||
|
||||
namespace SCJMapper_V2
|
||||
{
|
||||
[Example("DDS Cube Map", ExampleCategory.OpenGL, "2.x", Documentation = "DDSCubeMap")]
|
||||
public class T13_GLSL_Earth: GameWindow
|
||||
{
|
||||
public T13_GLSL_Earth( )
|
||||
: base( 800, 800 )
|
||||
{
|
||||
}
|
||||
|
||||
#region internal Fields
|
||||
|
||||
// Shader
|
||||
int VertexShaderObject, FragmentShaderObject, ProgramObject;
|
||||
const string VertexShaderFilename = "Data/Shaders/CubeMap_VS.glsl";
|
||||
const string FragmentShaderFilename = "Data/Shaders/CubeMap_FS.glsl";
|
||||
|
||||
// Textures
|
||||
const TextureUnit TMU0_Unit = TextureUnit.Texture0;
|
||||
const int TMU0_UnitInteger = 0;
|
||||
const string TMU0_Filename = "Data/Textures/earth-cubemap.dds";
|
||||
uint TMU0_Handle;
|
||||
TextureTarget TMU0_Target;
|
||||
|
||||
// DL
|
||||
DrawableShape sphere;
|
||||
|
||||
// Camera
|
||||
Vector3 EyePos = new Vector3( 0.0f, 0.0f, 6.0f );
|
||||
Vector3 Trackball = Vector3.Zero;
|
||||
|
||||
#endregion internal Fields
|
||||
|
||||
/// <summary>Setup OpenGL and load resources here.</summary>
|
||||
/// <param name="e">Not used.</param>
|
||||
protected override void OnLoad(EventArgs e)
|
||||
{
|
||||
this.VSync = VSyncMode.Off;
|
||||
|
||||
// Check for necessary capabilities:
|
||||
string extensions = GL.GetString(StringName.Extensions);
|
||||
if (!GL.GetString(StringName.Extensions).Contains("GL_ARB_shading_language"))
|
||||
{
|
||||
throw new NotSupportedException(String.Format("This example requires OpenGL 2.0. Found {0}. Aborting.",
|
||||
GL.GetString(StringName.Version).Substring(0, 3)));
|
||||
}
|
||||
|
||||
if (!extensions.Contains("GL_ARB_texture_compression") ||
|
||||
!extensions.Contains("GL_EXT_texture_compression_s3tc"))
|
||||
{
|
||||
throw new NotSupportedException("This example requires support for texture compression. Aborting.");
|
||||
}
|
||||
|
||||
#region GL State
|
||||
|
||||
GL.ClearColor( 0f, 0f, 0f, 0f );
|
||||
|
||||
GL.Disable( EnableCap.Dither );
|
||||
|
||||
GL.Enable( EnableCap.CullFace );
|
||||
GL.FrontFace( FrontFaceDirection.Ccw );
|
||||
GL.PolygonMode( MaterialFace.Front, PolygonMode.Fill );
|
||||
// GL.PolygonMode( MaterialFace.Back, PolygonMode.Line );
|
||||
|
||||
#endregion GL State
|
||||
|
||||
#region Shaders
|
||||
|
||||
string LogInfo;
|
||||
|
||||
// Load&Compile Vertex Shader
|
||||
|
||||
using ( StreamReader sr = new StreamReader( VertexShaderFilename ) )
|
||||
{
|
||||
VertexShaderObject = GL.CreateShader( ShaderType.VertexShader );
|
||||
GL.ShaderSource( VertexShaderObject, sr.ReadToEnd( ) );
|
||||
GL.CompileShader( VertexShaderObject );
|
||||
}
|
||||
|
||||
GL.GetShaderInfoLog( VertexShaderObject, out LogInfo );
|
||||
if ( LogInfo.Length > 0 && !LogInfo.Contains( "hardware" ) )
|
||||
Trace.WriteLine( "Vertex Shader failed!\nLog:\n" + LogInfo );
|
||||
else
|
||||
Trace.WriteLine( "Vertex Shader compiled without complaint." );
|
||||
|
||||
// Load&Compile Fragment Shader
|
||||
|
||||
using ( StreamReader sr = new StreamReader( FragmentShaderFilename ) )
|
||||
{
|
||||
FragmentShaderObject = GL.CreateShader( ShaderType.FragmentShader );
|
||||
GL.ShaderSource( FragmentShaderObject, sr.ReadToEnd( ) );
|
||||
GL.CompileShader( FragmentShaderObject );
|
||||
}
|
||||
GL.GetShaderInfoLog( FragmentShaderObject, out LogInfo );
|
||||
|
||||
if ( LogInfo.Length > 0 && !LogInfo.Contains( "hardware" ) )
|
||||
Trace.WriteLine( "Fragment Shader failed!\nLog:\n" + LogInfo );
|
||||
else
|
||||
Trace.WriteLine( "Fragment Shader compiled without complaint." );
|
||||
|
||||
// Link the Shaders to a usable Program
|
||||
ProgramObject = GL.CreateProgram( );
|
||||
GL.AttachShader( ProgramObject, VertexShaderObject );
|
||||
GL.AttachShader( ProgramObject, FragmentShaderObject );
|
||||
|
||||
// link it all together
|
||||
GL.LinkProgram( ProgramObject );
|
||||
|
||||
// flag ShaderObjects for delete when not used anymore
|
||||
GL.DeleteShader( VertexShaderObject );
|
||||
GL.DeleteShader( FragmentShaderObject );
|
||||
|
||||
int[] temp = new int[1];
|
||||
GL.GetProgram( ProgramObject, ProgramParameter.LinkStatus, out temp[0] );
|
||||
Trace.WriteLine( "Linking Program (" + ProgramObject + ") " + ( ( temp[0] == 1 ) ? "succeeded." : "FAILED!" ) );
|
||||
if ( temp[0] != 1 )
|
||||
{
|
||||
GL.GetProgramInfoLog( ProgramObject, out LogInfo );
|
||||
Trace.WriteLine( "Program Log:\n" + LogInfo );
|
||||
}
|
||||
|
||||
GL.GetProgram( ProgramObject, ProgramParameter.ActiveAttributes, out temp[0] );
|
||||
Trace.WriteLine( "Program registered " + temp[0] + " Attributes. (Should be 4: Pos, UV, Normal, Tangent)" );
|
||||
|
||||
Trace.WriteLine( "Tangent attribute bind location: " + GL.GetAttribLocation( ProgramObject, "AttributeTangent" ) );
|
||||
|
||||
Trace.WriteLine( "End of Shader build. GL Error: " + GL.GetError( ) );
|
||||
|
||||
#endregion Shaders
|
||||
|
||||
#region Textures
|
||||
|
||||
TextureLoaderParameters.FlipImages = false;
|
||||
TextureLoaderParameters.MagnificationFilter = TextureMagFilter.Linear;
|
||||
TextureLoaderParameters.MinificationFilter = TextureMinFilter.Linear;
|
||||
TextureLoaderParameters.WrapModeS = TextureWrapMode.ClampToEdge;
|
||||
TextureLoaderParameters.WrapModeT = TextureWrapMode.ClampToEdge;
|
||||
TextureLoaderParameters.EnvMode = TextureEnvMode.Modulate;
|
||||
|
||||
ImageDDS.LoadFromDisk( TMU0_Filename, out TMU0_Handle, out TMU0_Target );
|
||||
Trace.WriteLine( "Loaded " + TMU0_Filename + " with handle " + TMU0_Handle + " as " + TMU0_Target );
|
||||
|
||||
#endregion Textures
|
||||
|
||||
Trace.WriteLine( "End of Texture Loading. GL Error: " + GL.GetError( ) );
|
||||
Trace.WriteLine( "");
|
||||
|
||||
sphere = new SlicedSphere(1.5f, Vector3d.Zero, SlicedSphere.eSubdivisions.Four, new SlicedSphere.eDir[] { SlicedSphere.eDir.All }, true);
|
||||
|
||||
}
|
||||
|
||||
protected override void OnUnload(EventArgs e)
|
||||
{
|
||||
sphere.Dispose();
|
||||
|
||||
GL.DeleteProgram( ProgramObject );
|
||||
GL.DeleteTextures( 1, ref TMU0_Handle );
|
||||
|
||||
base.OnUnload( e );
|
||||
}
|
||||
|
||||
/// <summary>Respond to resize events here.</summary>
|
||||
/// <param name="e">Contains information on the new GameWindow size.</param>
|
||||
/// <remarks>There is no need to call the base implementation.</remarks>
|
||||
protected override void OnResize( EventArgs e )
|
||||
{
|
||||
GL.Viewport( 0, 0, Width, Height );
|
||||
|
||||
GL.MatrixMode( MatrixMode.Projection );
|
||||
Matrix4 p = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver4, Width / (float)Height, 0.1f, 10.0f);
|
||||
GL.LoadMatrix(ref p);
|
||||
|
||||
GL.MatrixMode( MatrixMode.Modelview );
|
||||
GL.LoadIdentity( );
|
||||
|
||||
base.OnResize( e );
|
||||
}
|
||||
|
||||
/// <summary>Add your game logic here.</summary>
|
||||
/// <param name="e">Contains timing information.</param>
|
||||
/// <remarks>There is no need to call the base implementation.</remarks>
|
||||
protected override void OnUpdateFrame( FrameEventArgs e )
|
||||
{
|
||||
base.OnUpdateFrame( e );
|
||||
|
||||
if ( Keyboard[OpenTK.Input.Key.Escape] )
|
||||
this.Exit( );
|
||||
if ( Keyboard[OpenTK.Input.Key.Space] )
|
||||
Trace.WriteLine( "GL: " + GL.GetError( ) );
|
||||
|
||||
Trackball.X = Mouse.X;
|
||||
Trackball.Y = Mouse.Y;
|
||||
Trackball.Z = Mouse.Wheel * 0.5f;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>Add your game rendering code here.</summary>
|
||||
/// <param name="e">Contains timing information.</param>
|
||||
/// <remarks>There is no need to call the base implementation.</remarks>
|
||||
protected override void OnRenderFrame(FrameEventArgs e)
|
||||
{
|
||||
this.Title = "FPS: " + (1 / e.Time).ToString("0.");
|
||||
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
|
||||
GL.UseProgram(ProgramObject);
|
||||
|
||||
#region Textures
|
||||
|
||||
GL.ActiveTexture(TMU0_Unit);
|
||||
GL.BindTexture(TMU0_Target, TMU0_Handle);
|
||||
|
||||
#endregion Textures
|
||||
|
||||
#region Uniforms
|
||||
|
||||
GL.Uniform1(GL.GetUniformLocation(ProgramObject, "Earth"), TMU0_UnitInteger);
|
||||
|
||||
#endregion Uniforms
|
||||
|
||||
GL.PushMatrix();
|
||||
Matrix4 temp = Matrix4.LookAt(EyePos, Vector3.Zero, Vector3.UnitY);
|
||||
GL.MultMatrix(ref temp);
|
||||
|
||||
GL.Rotate(Trackball.X, Vector3.UnitY);
|
||||
GL.Rotate(Trackball.Y, Vector3.UnitX);
|
||||
|
||||
#region Draw
|
||||
|
||||
GL.Color3(1f, 1f, 1f);
|
||||
|
||||
sphere.Draw();
|
||||
|
||||
#endregion Draw
|
||||
|
||||
GL.PopMatrix();
|
||||
|
||||
this.SwapBuffers();
|
||||
}
|
||||
|
||||
/// <summary>Entry point</summary>
|
||||
[STAThread]
|
||||
public static void Main( )
|
||||
{
|
||||
using ( T13_GLSL_Earth example = new T13_GLSL_Earth( ) )
|
||||
{
|
||||
Utilities.SetWindowTitle(example);
|
||||
example.Run( 30.0, 0.0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SCJMapper_V2.Shapes
|
||||
{
|
||||
public class Chunk
|
||||
{
|
||||
public VertexT2dN3dV3d[] Vertices;
|
||||
public uint[] Indices;
|
||||
|
||||
public uint VertexCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return (uint)Vertices.Length;
|
||||
}
|
||||
}
|
||||
public uint IndexCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return (uint)Indices.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public Chunk( uint vertexcount, uint indexcount )
|
||||
{
|
||||
Vertices = new VertexT2dN3dV3d[vertexcount];
|
||||
Indices = new uint[indexcount];
|
||||
}
|
||||
|
||||
public Chunk( ref VertexT2dN3dV3d[] vbo, ref uint[] ibo )
|
||||
{
|
||||
Vertices = new VertexT2dN3dV3d[vbo.Length];
|
||||
for ( int i = 0; i < Vertices.Length; i++ )
|
||||
{
|
||||
Vertices[i] = vbo[i];
|
||||
}
|
||||
Indices = new uint[ibo.Length];
|
||||
for ( int i = 0; i < Indices.Length; i++ )
|
||||
{
|
||||
Indices[i] = ibo[i];
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetArray( ref List<Chunk> c, out VertexT2dN3dV3d[] vbo, out uint[] ibo )
|
||||
{
|
||||
|
||||
uint VertexCounter = 0;
|
||||
uint IndexCounter = 0;
|
||||
|
||||
foreach ( Chunk ch in c )
|
||||
{
|
||||
VertexCounter += ch.VertexCount;
|
||||
IndexCounter += ch.IndexCount;
|
||||
}
|
||||
|
||||
vbo = new VertexT2dN3dV3d[VertexCounter];
|
||||
ibo = new uint[IndexCounter];
|
||||
|
||||
VertexCounter = 0;
|
||||
IndexCounter = 0;
|
||||
|
||||
foreach ( Chunk ch in c )
|
||||
{
|
||||
for ( int i = 0; i < ch.Vertices.Length; i++ )
|
||||
{
|
||||
vbo[VertexCounter + i] = ch.Vertices[i];
|
||||
}
|
||||
|
||||
for ( int i = 0; i < ch.Indices.Length; i++ )
|
||||
{
|
||||
ibo[IndexCounter + i] = ch.Indices[i] + VertexCounter;
|
||||
}
|
||||
|
||||
VertexCounter += (uint)ch.VertexCount;
|
||||
IndexCounter += (uint)ch.IndexCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,181 +0,0 @@
|
||||
#region --- License ---
|
||||
/* Copyright (c) 2006, 2007 Stefanos Apostolopoulos
|
||||
* See license.txt for license info
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
|
||||
namespace SCJMapper_V2.Shapes
|
||||
{
|
||||
// Abstract base class for procedurally generated geometry
|
||||
//
|
||||
// All classes derived from it must produce Counter-Clockwise (CCW) primitives.
|
||||
// Derived classes must create a single VBO and IBO, without primitive restarts for strips.
|
||||
// Uses an double-precision all-possible-attributes VertexT2dN3dV3d Array internally.
|
||||
// Cannot directly use VBO, but has Get-methods to retrieve VBO-friendly data.
|
||||
// Can use a Display List to prevent repeated immediate mode draws.
|
||||
//
|
||||
|
||||
public abstract class DrawableShape: IDisposable
|
||||
{
|
||||
protected PrimitiveType PrimitiveMode;
|
||||
protected VertexT2dN3dV3d[] VertexArray;
|
||||
protected uint[] IndexArray;
|
||||
|
||||
public int GetTriangleCount
|
||||
{
|
||||
get
|
||||
{
|
||||
switch ( PrimitiveMode )
|
||||
{
|
||||
case PrimitiveType.Triangles:
|
||||
if ( IndexArray != null )
|
||||
{
|
||||
return IndexArray.Length / 3;
|
||||
} else
|
||||
{
|
||||
return VertexArray.Length / 3;
|
||||
}
|
||||
// break;
|
||||
default: throw new NotImplementedException("Unknown primitive type.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Display List
|
||||
|
||||
private bool UseDisplayList;
|
||||
private int DisplayListHandle = 0;
|
||||
|
||||
#endregion Display List
|
||||
|
||||
public DrawableShape( bool useDisplayList )
|
||||
{
|
||||
UseDisplayList = useDisplayList;
|
||||
PrimitiveMode = PrimitiveType.Triangles;
|
||||
VertexArray = null;
|
||||
IndexArray = null;
|
||||
}
|
||||
|
||||
#region Convert to VBO
|
||||
|
||||
public void GetArraysforVBO( out PrimitiveType primitives, out VertexT2dN3dV3d[] vertices, out uint[] indices )
|
||||
{
|
||||
primitives = PrimitiveMode;
|
||||
|
||||
vertices = new VertexT2dN3dV3d[VertexArray.Length];
|
||||
for (uint i = 0; i < VertexArray.Length; i++)
|
||||
{
|
||||
vertices[i].TexCoord = VertexArray[i].TexCoord;
|
||||
vertices[i].Normal = VertexArray[i].Normal;
|
||||
vertices[i].Position = VertexArray[i].Position;
|
||||
}
|
||||
|
||||
indices = IndexArray;
|
||||
}
|
||||
|
||||
public void GetArraysforVBO( out PrimitiveType primitives, out VertexT2fN3fV3f[] vertices, out uint[] indices )
|
||||
{
|
||||
primitives = PrimitiveMode;
|
||||
|
||||
vertices = new VertexT2fN3fV3f[VertexArray.Length];
|
||||
for (uint i = 0; i < VertexArray.Length; i++)
|
||||
{
|
||||
vertices[i].TexCoord = (Vector2)VertexArray[i].TexCoord;
|
||||
vertices[i].Normal = (Vector3)VertexArray[i].Normal;
|
||||
vertices[i].Position = (Vector3)VertexArray[i].Position;
|
||||
}
|
||||
|
||||
indices = IndexArray;
|
||||
}
|
||||
|
||||
public void GetArraysforVBO( out PrimitiveType primitives, out VertexT2hN3hV3h[] vertices, out uint[] indices )
|
||||
{
|
||||
primitives = PrimitiveMode;
|
||||
|
||||
vertices = new VertexT2hN3hV3h[VertexArray.Length];
|
||||
for (uint i = 0; i < VertexArray.Length; i++)
|
||||
{
|
||||
vertices[i].TexCoord = (Vector2h)VertexArray[i].TexCoord;
|
||||
vertices[i].Normal = (Vector3h)VertexArray[i].Normal;
|
||||
vertices[i].Position = (Vector3h)VertexArray[i].Position;
|
||||
}
|
||||
|
||||
indices = IndexArray;
|
||||
}
|
||||
|
||||
#endregion Convert to VBO
|
||||
|
||||
private void DrawImmediateMode()
|
||||
{
|
||||
GL.Begin( PrimitiveMode );
|
||||
{
|
||||
if ( IndexArray == null )
|
||||
foreach ( VertexT2dN3dV3d v in VertexArray )
|
||||
{
|
||||
GL.TexCoord2( v.TexCoord.X, v.TexCoord.Y );
|
||||
GL.Normal3( v.Normal.X, v.Normal.Y, v.Normal.Z );
|
||||
GL.Vertex3( v.Position.X, v.Position.Y, v.Position.Z );
|
||||
} else
|
||||
{
|
||||
for ( uint i = 0; i < IndexArray.Length; i++ )
|
||||
{
|
||||
uint index = IndexArray[i];
|
||||
GL.TexCoord2( VertexArray[index].TexCoord.X, VertexArray[index].TexCoord.Y );
|
||||
GL.Normal3( VertexArray[index].Normal.X, VertexArray[index].Normal.Y, VertexArray[index].Normal.Z );
|
||||
GL.Vertex3( VertexArray[index].Position.X, VertexArray[index].Position.Y, VertexArray[index].Position.Z );
|
||||
}
|
||||
}
|
||||
}
|
||||
GL.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Does not touch any state/matrices. Does call Begin/End and Vertex&Co.
|
||||
/// Creates and compiles a display list if not present yet. Requires an OpenGL context.
|
||||
/// </summary>
|
||||
public void Draw()
|
||||
{
|
||||
if ( !UseDisplayList )
|
||||
DrawImmediateMode();
|
||||
else
|
||||
if ( DisplayListHandle == 0 )
|
||||
{
|
||||
if ( VertexArray == null )
|
||||
throw new Exception("Cannot draw null Vertex Array.");
|
||||
DisplayListHandle = GL.GenLists( 1 );
|
||||
GL.NewList( DisplayListHandle, ListMode.CompileAndExecute );
|
||||
DrawImmediateMode();
|
||||
GL.EndList();
|
||||
} else
|
||||
GL.CallList( DisplayListHandle );
|
||||
}
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
/// <summary>
|
||||
/// Removes reference to VertexArray and IndexArray.
|
||||
/// Deletes the Display List, so it requires an OpenGL context.
|
||||
/// The instance is effectively destroyed.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if ( VertexArray != null )
|
||||
VertexArray = null;
|
||||
if ( IndexArray != null )
|
||||
IndexArray = null;
|
||||
if ( DisplayListHandle != 0 )
|
||||
{
|
||||
GL.DeleteLists( DisplayListHandle, 1 );
|
||||
DisplayListHandle = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
@ -1,196 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using OpenTK;
|
||||
|
||||
namespace SCJMapper_V2.Shapes
|
||||
{
|
||||
public sealed class SlicedSphere: DrawableShape
|
||||
{
|
||||
public enum eSubdivisions
|
||||
{
|
||||
Zero = 0,
|
||||
One = 1,
|
||||
Two = 2,
|
||||
Three = 3,
|
||||
Four = 4,
|
||||
Five=5,
|
||||
Six=6,
|
||||
Seven=7,
|
||||
Eight=8,
|
||||
}
|
||||
|
||||
public enum eDir
|
||||
{
|
||||
All,
|
||||
FrontTopRight,
|
||||
FrontBottomRight,
|
||||
FrontBottomLeft,
|
||||
FrontTopLeft,
|
||||
BackTopRight,
|
||||
BackBottomRight,
|
||||
BackBottomLeft,
|
||||
BackTopLeft,
|
||||
|
||||
}
|
||||
|
||||
public SlicedSphere( double radius, Vector3d offset, eSubdivisions subdivs, eDir[] sides, bool useDL )
|
||||
: base( useDL )
|
||||
{
|
||||
double Diameter = radius;
|
||||
|
||||
PrimitiveMode = OpenTK.Graphics.OpenGL.PrimitiveType.Triangles;
|
||||
|
||||
if ( sides[0] == eDir.All )
|
||||
{
|
||||
sides = new eDir[] { eDir.FrontTopRight,
|
||||
eDir.FrontBottomRight,
|
||||
eDir.FrontBottomLeft,
|
||||
eDir.FrontTopLeft,
|
||||
eDir.BackTopRight,
|
||||
eDir.BackBottomRight,
|
||||
eDir.BackBottomLeft,
|
||||
eDir.BackTopLeft,};
|
||||
}
|
||||
|
||||
VertexArray = new VertexT2dN3dV3d[sides.Length * 3];
|
||||
IndexArray = new uint[sides.Length * 3];
|
||||
|
||||
uint counter = 0;
|
||||
foreach ( eDir s in sides )
|
||||
{
|
||||
GetDefaultVertices( s, Diameter, out VertexArray[counter + 0], out VertexArray[counter + 1], out VertexArray[counter + 2] );
|
||||
IndexArray[counter + 0] = counter + 0;
|
||||
IndexArray[counter + 1] = counter + 1;
|
||||
IndexArray[counter + 2] = counter + 2;
|
||||
counter += 3;
|
||||
}
|
||||
|
||||
if ( subdivs != eSubdivisions.Zero )
|
||||
{
|
||||
|
||||
for ( int s = 0; s < (int)subdivs; s++ )
|
||||
{
|
||||
#region Assemble Chunks and convert to Arrays
|
||||
List<Chunk> AllChunks = new List<Chunk>();
|
||||
for ( uint i = 0; i < IndexArray.Length; i += 3 )
|
||||
{
|
||||
Chunk chu;
|
||||
Subdivide( Diameter,
|
||||
ref VertexArray[IndexArray[i + 0]],
|
||||
ref VertexArray[IndexArray[i + 1]],
|
||||
ref VertexArray[IndexArray[i + 2]],
|
||||
out chu );
|
||||
AllChunks.Add( chu );
|
||||
}
|
||||
|
||||
Chunk.GetArray( ref AllChunks, out VertexArray, out IndexArray );
|
||||
AllChunks.Clear();
|
||||
#endregion Assemble Chunks and convert to Arrays
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i<VertexArray.Length;i++)
|
||||
{
|
||||
Vector3d.Add(ref VertexArray[i].Position, ref offset, out VertexArray[i].Position);
|
||||
}
|
||||
}
|
||||
|
||||
private void GetDefaultVertices( eDir s, double scale, out VertexT2dN3dV3d first, out VertexT2dN3dV3d second, out VertexT2dN3dV3d third )
|
||||
{
|
||||
VertexT2dN3dV3d t1 = new VertexT2dN3dV3d(),
|
||||
t2 = new VertexT2dN3dV3d(),
|
||||
t3 = new VertexT2dN3dV3d();
|
||||
switch ( s )
|
||||
{
|
||||
case eDir.FrontTopRight:
|
||||
t1 = new VertexT2dN3dV3d( new Vector2d( 0.5, 1.0 ), Vector3d.UnitY, Vector3d.UnitY * scale );
|
||||
t2 = new VertexT2dN3dV3d( new Vector2d( 0.0, 0.0 ), Vector3d.UnitZ, Vector3d.UnitZ * scale );
|
||||
t3 = new VertexT2dN3dV3d( new Vector2d( 0.5, 0.0 ), Vector3d.UnitX, Vector3d.UnitX * scale );
|
||||
break;
|
||||
case eDir.FrontBottomRight:
|
||||
t1 = new VertexT2dN3dV3d( new Vector2d( 0.5, 0.0 ), Vector3d.UnitX, Vector3d.UnitX * scale );
|
||||
t2 = new VertexT2dN3dV3d( new Vector2d( 0.0, 0.0 ), Vector3d.UnitZ, Vector3d.UnitZ * scale );
|
||||
t3 = new VertexT2dN3dV3d( new Vector2d( 0.5, 1.0 ), -Vector3d.UnitY, -Vector3d.UnitY * scale );
|
||||
break;
|
||||
case eDir.FrontBottomLeft:
|
||||
t1 = new VertexT2dN3dV3d( new Vector2d( 0.5, 0.0 ), Vector3d.UnitX, Vector3d.UnitX * scale );
|
||||
t2 = new VertexT2dN3dV3d( new Vector2d( 0.5, 1.0 ), -Vector3d.UnitY, -Vector3d.UnitY * scale );
|
||||
t3 = new VertexT2dN3dV3d( new Vector2d( 1.0, 0.0 ), -Vector3d.UnitZ, -Vector3d.UnitZ * scale );
|
||||
break;
|
||||
case eDir.FrontTopLeft:
|
||||
t1 = new VertexT2dN3dV3d( new Vector2d( 1.0, 0.0 ), -Vector3d.UnitZ, -Vector3d.UnitZ * scale );
|
||||
t2 = new VertexT2dN3dV3d( new Vector2d( 0.5, 1.0 ), Vector3d.UnitY, Vector3d.UnitY * scale );
|
||||
t3 = new VertexT2dN3dV3d( new Vector2d( 0.5, 0.0 ), Vector3d.UnitX, Vector3d.UnitX * scale );
|
||||
break;
|
||||
case eDir.BackTopRight:
|
||||
t1 = new VertexT2dN3dV3d( new Vector2d( 0.5, 1.0 ), Vector3d.UnitY, Vector3d.UnitY * scale );
|
||||
t2 = new VertexT2dN3dV3d( new Vector2d( 0.0, 1.0 ), -Vector3d.UnitX, -Vector3d.UnitX * scale );
|
||||
t3 = new VertexT2dN3dV3d( new Vector2d( 0.0, 0.0 ), Vector3d.UnitZ, Vector3d.UnitZ * scale );
|
||||
break;
|
||||
case eDir.BackBottomRight:
|
||||
t1 = new VertexT2dN3dV3d( new Vector2d( 0.5, 1.0 ), -Vector3d.UnitY, -Vector3d.UnitY * scale );
|
||||
t2 = new VertexT2dN3dV3d( new Vector2d( 0.0, 0.0 ), Vector3d.UnitZ, Vector3d.UnitZ * scale );
|
||||
t3 = new VertexT2dN3dV3d( new Vector2d( 0.0, 1.0 ), -Vector3d.UnitX, -Vector3d.UnitX * scale );
|
||||
break;
|
||||
case eDir.BackBottomLeft:
|
||||
t1 = new VertexT2dN3dV3d( new Vector2d( 0.5, 1.0 ), -Vector3d.UnitY, -Vector3d.UnitY * scale );
|
||||
t2 = new VertexT2dN3dV3d( new Vector2d( 1.0, 1.0 ), -Vector3d.UnitX, -Vector3d.UnitX * scale );
|
||||
t3 = new VertexT2dN3dV3d( new Vector2d( 1.0, 0.0 ), -Vector3d.UnitZ, -Vector3d.UnitZ * scale );
|
||||
break;
|
||||
case eDir.BackTopLeft:
|
||||
t1 = new VertexT2dN3dV3d( new Vector2d( 0.5, 1.0 ), Vector3d.UnitY, Vector3d.UnitY * scale );
|
||||
t2 = new VertexT2dN3dV3d( new Vector2d( 1.0, 0.0 ), -Vector3d.UnitZ, -Vector3d.UnitZ * scale );
|
||||
t3 = new VertexT2dN3dV3d( new Vector2d( 1.0, 1.0 ), -Vector3d.UnitX, -Vector3d.UnitX * scale );
|
||||
break;
|
||||
}
|
||||
first = t1;
|
||||
second = t2;
|
||||
third = t3;
|
||||
}
|
||||
|
||||
|
||||
private void Subdivide( double Scale, ref VertexT2dN3dV3d first, ref VertexT2dN3dV3d second, ref VertexT2dN3dV3d third, out Chunk c )
|
||||
{
|
||||
c = new Chunk(6, 12);
|
||||
|
||||
c.Vertices[0] = first;
|
||||
|
||||
Vector3d.Lerp(ref first.Position, ref second.Position, 0.5,out c.Vertices[1].Normal );
|
||||
c.Vertices[1].Normal.Normalize();
|
||||
c.Vertices[1].Position = c.Vertices[1].Normal * Scale;
|
||||
Vector2d.Lerp( ref first.TexCoord, ref second.TexCoord, 0.5, out c.Vertices[1].TexCoord );
|
||||
|
||||
Vector3d.Lerp( ref third.Position, ref first.Position, 0.5, out c.Vertices[2].Normal );
|
||||
c.Vertices[2].Normal.Normalize();
|
||||
c.Vertices[2].Position = c.Vertices[2].Normal * Scale;
|
||||
Vector2d.Lerp( ref third.TexCoord, ref first.TexCoord, 0.5, out c.Vertices[2].TexCoord );
|
||||
|
||||
c.Vertices[3] = second;
|
||||
|
||||
Vector3d.Lerp( ref second.Position, ref third.Position, 0.5, out c.Vertices[4].Normal );
|
||||
c.Vertices[4].Normal.Normalize();
|
||||
c.Vertices[4].Position = c.Vertices[4].Normal * Scale;
|
||||
Vector2d.Lerp( ref second.TexCoord, ref third.TexCoord, 0.5, out c.Vertices[4].TexCoord );
|
||||
|
||||
c.Vertices[5] = third;
|
||||
|
||||
#region Indices
|
||||
c.Indices[0]=0;
|
||||
c.Indices[1]=1;
|
||||
c.Indices[2]=2;
|
||||
c.Indices[3]=2;
|
||||
c.Indices[4]=1;
|
||||
c.Indices[5]=4;
|
||||
c.Indices[6]=1;
|
||||
c.Indices[7]=3;
|
||||
c.Indices[8]=4;
|
||||
c.Indices[9]=2;
|
||||
c.Indices[10]=4;
|
||||
c.Indices[11]=5;
|
||||
#endregion Indices
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
using System;
|
||||
|
||||
using OpenTK;
|
||||
|
||||
namespace SCJMapper_V2.Shapes
|
||||
{
|
||||
public struct VertexT2dN3dV3d
|
||||
{
|
||||
public Vector2d TexCoord;
|
||||
public Vector3d Normal;
|
||||
public Vector3d Position;
|
||||
|
||||
public VertexT2dN3dV3d( Vector2d texcoord, Vector3d normal, Vector3d position )
|
||||
{
|
||||
TexCoord = texcoord;
|
||||
Normal = normal;
|
||||
Position = position;
|
||||
}
|
||||
}
|
||||
|
||||
public struct VertexT2fN3fV3f
|
||||
{
|
||||
public Vector2 TexCoord;
|
||||
public Vector3 Normal;
|
||||
public Vector3 Position;
|
||||
}
|
||||
|
||||
public struct VertexT2hN3hV3h
|
||||
{
|
||||
public Vector2h TexCoord;
|
||||
public Vector3h Normal;
|
||||
public Vector3h Position;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue