Skip to content
This repository has been archived by the owner on Feb 18, 2022. It is now read-only.

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
Lighting, debug keys
  • Loading branch information
fonsp committed Oct 26, 2014
1 parent 4870376 commit 095a79e
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 67 deletions.
2 changes: 1 addition & 1 deletion GraphicsEngine/Core/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public override void Render(int pass)
GL.BindBuffer(BufferTarget.ElementArrayBuffer, mesh.VBOids[1]);
GL.InterleavedArrays(InterleavedArrayFormat.T2fN3fV3f, 0, IntPtr.Zero);
GL.DrawElements(BeginMode.Triangles, mesh.vertexArray.Length, DrawElementsType.UnsignedInt, 0);

GL.DisableClientState(ArrayCap.TextureCoordArray);
GL.DisableClientState(ArrayCap.NormalArray);
GL.DisableClientState(ArrayCap.VertexArray);
Expand Down
52 changes: 49 additions & 3 deletions GraphicsEngine/Core/Shader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void main()
gl_Position = gl_ProjectionMatrix * v;*/
gl_Position = ftransform();
gl_FrontColor = vec4(vec3(1.0 / (gl_Position.w / 2000.0 + 1.0)), 1.0);
gl_FrontColor = vec4(gl_Color.xyz, 1.0 / (gl_Position.w / 2000.0 + 1.0));
gl_TexCoord[0] = gl_MultiTexCoord0;
}",
fragmentShader = @"
Expand All @@ -146,7 +146,7 @@ void main()
void main()
{
float a = sqrt(intensity);
gl_FragColor = gl_Color * (texture2D(tex, gl_TexCoord[0].xy) * (vec4(a, a, a, 1.0) * gl_LightSource[0].diffuse + vec4(1.0-a, 1.0-a, 1.0-a, 1.0) * gl_LightSource[0].ambient));
gl_FragColor = vec4(vec3(gl_Color.w), 1.0) * (texture2D(tex, gl_TexCoord[0].xy) * (vec4(a, a, a, 1.0) * gl_LightSource[0].diffuse + vec4(1.0-a, 1.0-a, 1.0-a, 1.0) * gl_LightSource[0].ambient));
}"
};
}
Expand Down Expand Up @@ -181,9 +181,9 @@ public static Shader unlitShader
void main()
{
gl_FrontColor = gl_Color;
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_FrontColor = gl_Color;
}",
fragmentShader = @"
#version 120
Expand Down Expand Up @@ -215,6 +215,52 @@ public static Shader unlitShaderCompiled
}
}

public static Shader depthShader
{
get
{
return new Shader
{
vertexShader = @"
#version 120
uniform float time;
void main()
{
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_FrontColor = vec4(gl_Color.xyz, 1.0 / (gl_Position.w / 2000.0 + 1.0));
}",
fragmentShader = @"
#version 120
uniform float time;
uniform sampler2D tex;
void main()
{
gl_FragColor = texture2D(tex, gl_TexCoord[0].xy) * vec4(gl_Color.xyz, 1.0) * vec4(vec3(gl_Color.w), 1.0);
}"
};
}
}

private static Shader depthShaderCompiledi;
public static Shader depthShaderCompiled
{
get
{
if(depthShaderCompiledi == null)
{
depthShaderCompiledi = depthShader;
}
if(depthShaderCompiledi.Compiled == false)
{
depthShaderCompiledi.GenerateShaders();
}
return depthShaderCompiledi;
}
}

public static Shader wireframeShader
{
get
Expand Down
5 changes: 2 additions & 3 deletions Resim/Game.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
; ---------------------------------
; Game settings - DO NOT MODIFY
; ---------------------------------
; ---------------------------------
; Copyright 2013, Fons van der Plas
; ---------------------------------

; Player
int walkingSpeed 3500
Expand All @@ -13,6 +10,8 @@ int walkHeight 170
int crouchHeight 90
int gravity 2000
double playerFriction .0001
int riseSpeed 500
double groundedCorrection 10

; Other
bool thisIsABool true
4 changes: 2 additions & 2 deletions Resim/Program/InitGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public partial class Game
private Random random = new Random();

private List<CollisionAABB> mapCollision = new List<CollisionAABB>();

public override void InitGame()
{
#region Entities
Expand Down Expand Up @@ -109,7 +109,7 @@ public override void InitGame()

RootNode.Instance.Add(monster);
RootNode.Instance.Add(skybox);
//RootNode.Instance.Add(ground);
RootNode.Instance.Add(ground);
RootNode.Instance.Add(map);
/*map.Add(map0a);
map.Add(map0b);
Expand Down
18 changes: 9 additions & 9 deletions Resim/Program/ProgramEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private void DebugInputReceived(object sender, HudDebugInputEventArgs e)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

if(!String.IsNullOrEmpty(e.InputArray[0]))
if(e.InputArray.Length > 0 && !String.IsNullOrEmpty(e.InputArray[0]))
{
switch(e.InputArray[0])
{
Expand All @@ -24,32 +24,32 @@ private void DebugInputReceived(object sender, HudDebugInputEventArgs e)
RenderWindow.Instance.Exit();
break;
case "set":
if (e.InputArray.Length > 1 && !String.IsNullOrEmpty(e.InputArray[1]))
if(e.InputArray.Length > 1 && !String.IsNullOrEmpty(e.InputArray[1]))
{
switch (e.InputArray[1])
switch(e.InputArray[1])
{
case "timeMult":
if (!String.IsNullOrEmpty(e.InputArray[2]))
if(e.InputArray.Length > 2 && !String.IsNullOrEmpty(e.InputArray[2]))
{
RenderWindow.Instance.timeMultiplier = Convert.ToDouble(e.InputArray[2]);
hudDebug.AddLine("timeMult was set to " + RenderWindow.Instance.timeMultiplier);
}
break;
case "walkSpeed":
if (!String.IsNullOrEmpty(e.InputArray[2]))
if(e.InputArray.Length > 2 && !String.IsNullOrEmpty(e.InputArray[2]))
{
walkSpeed = (int) Convert.ToDouble(e.InputArray[2]);
walkSpeed = (int)Convert.ToDouble(e.InputArray[2]);
hudDebug.AddLine("walkSpeed was set to " + walkSpeed);
}
break;
case "VSync":
if (!String.IsNullOrEmpty(e.InputArray[2]))
if(e.InputArray.Length > 2 && !String.IsNullOrEmpty(e.InputArray[2]))
{
try
{
RenderWindow.Instance.VSync = (VSyncMode) Enum.Parse(typeof (VSyncMode), e.InputArray[2], true);
RenderWindow.Instance.VSync = (VSyncMode)Enum.Parse(typeof(VSyncMode), e.InputArray[2], true);
}
catch (Exception exception)
catch(Exception exception)
{
}
hudDebug.AddLine("VSync was set to " + RenderWindow.Instance.VSync);
Expand Down
103 changes: 54 additions & 49 deletions Resim/Program/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,52 +69,6 @@ public override void Update(float timeSinceLastUpdate)
}
crossHair.isVisible = true;
}*/
Vector3 raydir = Vector3.Zero;
raydir.Z = (float)-Math.Cos(fpsCam.X);
raydir.X = (float)Math.Sin(fpsCam.X);
raydir.Y = (float)Math.Tan(fpsCam.Y);
raydir.Normalize();

if(!InputManager.IsButtonDown(MouseButton.Right))
{
if(mouseDown)
{
Camera.Instance.position += 500f * raydir;
}
mouseDown = false;
monster.isVisible = false;
}
else
{
mouseDown = true;
monster.isVisible = true;
monster.position = Camera.Instance.position + 500f * raydir - new Vector3(0, 80, 0);
}

if(InputManager.IsKeyDown(Key.Left))
{
monster.position.X -= 500f * timeSinceLastUpdate;
monsterAABB.Translate(new Vector3(-500f * timeSinceLastUpdate, 0f, 0f));
}

if(InputManager.IsKeyDown(Key.Right))
{
monster.position.X += 500f * timeSinceLastUpdate;
monsterAABB.Translate(new Vector3(500f * timeSinceLastUpdate, 0f, 0f));
}

if(InputManager.IsKeyDown(Key.Up))
{
monster.position.Y += 500f * timeSinceLastUpdate;
monsterAABB.Translate(new Vector3(0f, 500f * timeSinceLastUpdate, 0f));
}

if(InputManager.IsKeyDown(Key.Down))
{
monster.position.Y -= 500f * timeSinceLastUpdate;
monsterAABB.Translate(new Vector3(0f, -500f * timeSinceLastUpdate, 0f));
}

#endregion
#region Movement

Expand Down Expand Up @@ -168,7 +122,7 @@ public override void Update(float timeSinceLastUpdate)
if(dist <= playerHeight && dist != -1)
{
grounded = true;
Camera.Instance.position.Y += Math.Min(500 * timeSinceLastUpdate, playerHeight - dist);
Camera.Instance.position.Y += Math.Min(config.GetInt("riseSpeed") * timeSinceLastUpdate, playerHeight - dist);
}

// X vel
Expand Down Expand Up @@ -258,8 +212,8 @@ public override void Update(float timeSinceLastUpdate)
#region Jumping/Gravity
if(grounded)
{
Camera.Instance.velocity.Y = 0;

Camera.Instance.velocity.Y = Math.Max(Camera.Instance.velocity.Y, 0);
Camera.Instance.position.Y -= (float)config.GetDouble("groundedCorrection") * timeSinceLastUpdate; //roundoff error correction
if(InputManager.IsKeyDown(Key.Space))
{
Camera.Instance.velocity.Y = config.GetInt("jumpForce");
Expand Down Expand Up @@ -296,6 +250,57 @@ public override void Update(float timeSinceLastUpdate)

Camera.Instance.position += cameraBobDelta;

#endregion
#region Other
Vector3 raydir = Vector3.Zero;
raydir.Z = (float)-Math.Cos(fpsCam.X);
raydir.X = (float)Math.Sin(fpsCam.X);
raydir.Y = (float)Math.Tan(fpsCam.Y);
raydir.Normalize();

if(!InputManager.IsButtonDown(MouseButton.Right))
{
if(mouseDown)
{
Camera.Instance.position += 500f * raydir;
}
mouseDown = false;
monster.isVisible = false;
}
else
{
mouseDown = true;
monster.isVisible = true;
monster.position = Camera.Instance.position + 500f * raydir - new Vector3(0, 80, 0);
}

if(InputManager.IsKeyDown(Key.Left))
{
monster.position.X -= 500f * timeSinceLastUpdate;
monsterAABB.Translate(new Vector3(-500f * timeSinceLastUpdate, 0f, 0f));
}

if(InputManager.IsKeyDown(Key.Right))
{
monster.position.X += 500f * timeSinceLastUpdate;
monsterAABB.Translate(new Vector3(500f * timeSinceLastUpdate, 0f, 0f));
}

if(InputManager.IsKeyDown(Key.Up))
{
monster.position.Y += 500f * timeSinceLastUpdate;
monsterAABB.Translate(new Vector3(0f, 500f * timeSinceLastUpdate, 0f));
}

if(InputManager.IsKeyDown(Key.Down))
{
monster.position.Y -= 500f * timeSinceLastUpdate;
monsterAABB.Translate(new Vector3(0f, -500f * timeSinceLastUpdate, 0f));
}

ground.isVisible = InputManager.IsKeyToggled(Key.Number1);
map1.mesh.shader = InputManager.IsKeyToggled(Key.Number2) ? Shader.depthShaderCompiled : null;

#endregion
#region HUD

Expand Down

0 comments on commit 095a79e

Please sign in to comment.