Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles authored and Charles committed Jan 11, 2017
1 parent 3b2b566 commit 3955a70
Show file tree
Hide file tree
Showing 29 changed files with 2,170 additions and 0 deletions.
Binary file added Possiblev7.zip
Binary file not shown.
28 changes: 28 additions & 0 deletions TerrainFPS.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TerrainFPS", "TerrainFPS\TerrainFPS.vcxproj", "{2E726080-001D-4FF2-B0F2-1D15F854937E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2E726080-001D-4FF2-B0F2-1D15F854937E}.Debug|x64.ActiveCfg = Debug|x64
{2E726080-001D-4FF2-B0F2-1D15F854937E}.Debug|x64.Build.0 = Debug|x64
{2E726080-001D-4FF2-B0F2-1D15F854937E}.Debug|x86.ActiveCfg = Debug|Win32
{2E726080-001D-4FF2-B0F2-1D15F854937E}.Debug|x86.Build.0 = Debug|Win32
{2E726080-001D-4FF2-B0F2-1D15F854937E}.Release|x64.ActiveCfg = Release|x64
{2E726080-001D-4FF2-B0F2-1D15F854937E}.Release|x64.Build.0 = Release|x64
{2E726080-001D-4FF2-B0F2-1D15F854937E}.Release|x86.ActiveCfg = Release|Win32
{2E726080-001D-4FF2-B0F2-1D15F854937E}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file added TerrainFPS/182.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
157 changes: 157 additions & 0 deletions TerrainFPS/BasicFS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#version 330 core

struct Material {
vec3 ambient;
vec3 diffuse;
vec3 specular;
float shininess;
};

struct PointLight {
vec3 position;

float constant;
float linear;
float quadratic;

vec3 ambient;
vec3 diffuse;
vec3 specular;
};

struct DirLight {
vec3 direction;

vec3 ambient;
vec3 diffuse;
vec3 specular;
};

struct SpotLight {
vec3 position;
vec3 direction;
float cutOff;
float outerCutOff;

float constant;
float linear;
float quadratic;

vec3 ambient;
vec3 diffuse;
vec3 specular;
};

in vec3 FragPos;
in vec3 Normal;
in vec3 ourColor;
in vec2 TexCoords;

out vec4 color;

uniform vec3 viewPos;
uniform Material material;
uniform DirLight dirLight;
uniform SpotLight spotLight;
uniform float time;
uniform float crazyStrength;

// Texture samplers
uniform sampler2D myTexture;

// Function prototypes
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir);
vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir);
vec3 CalcSpotLight(SpotLight light, vec3 norm, vec3 fragPos, vec3 viewDir);

void main()
{
// Properties
vec3 norm = normalize(Normal);
vec3 viewDir = normalize(viewPos - FragPos);

// Directional lighting (sun)
vec3 result = vec3(texture(myTexture, TexCoords));
result *= 0.35;
result += 0.85f;
result *= ourColor;
result *= CalcDirLight(dirLight, norm, viewDir);
// Flash light
result += CalcSpotLight(spotLight, norm, FragPos, viewDir);
result *= (1 - crazyStrength);
vec3 timeColor = vec3(abs(sin(FragPos.y + (time))*sin(FragPos.x + cos(time))), abs(cos(FragPos.z + time)*cos(FragPos.x + sin(time))),abs(sin(FragPos.z + time)*cos(FragPos.x + time)));
timeColor *= crazyStrength;
result += timeColor;

color = vec4(result, 1.0);
}

// Calculates the color when using a directional light.
vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir)
{
vec3 lightDir = normalize(-light.direction);
// Diffuse shading
float diff = max(dot(normal, lightDir), 0.0);
// Specular shading
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
// Combine results
vec3 ambient = light.ambient;
vec3 diffuse = light.diffuse * diff;
vec3 specular = light.specular * spec;
return (ambient + diffuse + specular);
}

// Calculates the color when using a point light.
vec3 CalcPointLight(PointLight light, vec3 normal, vec3 fragPos, vec3 viewDir)
{
vec3 lightDir = normalize(light.position - fragPos);
// Diffuse shading
float diff = max(dot(normal, lightDir), 0.0);
// Specular shading
vec3 reflectDir = reflect(-lightDir, normal);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
// Attenuation
float distance = length(light.position - fragPos);
float attenuation = 1.0f / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
// Combine results
vec3 ambient = light.ambient;
vec3 diffuse = light.diffuse * diff;
vec3 specular = light.specular * spec;
ambient *= attenuation;
diffuse *= attenuation;
specular *= attenuation;
return (ambient + diffuse + specular);
}

vec3 CalcSpotLight(SpotLight light, vec3 norm, vec3 fragPos, vec3 viewDir){
// Spotlight (soft edges)
// Ambient
vec3 ambient = light.ambient;

// Diffuse
vec3 lightDir = normalize(light.position - FragPos);
float diff = max(dot(norm, lightDir), 0.0);
vec3 diffuse = light.diffuse * diff;

// Specular
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
vec3 specular = light.specular * spec;

// Spotlight (soft edges)
float theta = dot(lightDir, normalize(-light.direction));
float epsilon = (light.cutOff - light.outerCutOff);
float intensity = clamp((theta - light.outerCutOff) / epsilon, 0.0, 1.0);
diffuse *= intensity;
specular *= intensity;

// Attenuation
float distance = length(light.position - FragPos);
float attenuation = 1.0f / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
ambient *= attenuation;
diffuse *= attenuation;
specular *= attenuation;

return (ambient + diffuse + specular);
}
23 changes: 23 additions & 0 deletions TerrainFPS/BasicVS.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#version 330 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec3 color;
layout (location = 2) in vec3 normal;
layout (location = 3) in vec2 texCoord;

out vec3 ourColor;
out vec3 Normal;
out vec3 FragPos;
out vec2 TexCoords;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main()
{
gl_Position = projection * view * model * vec4(position, 1.0f);
ourColor = color;
FragPos = vec3(model * vec4(position, 1.0f));
Normal = mat3(transpose(inverse(model))) * normal;
TexCoords = texCoord;
}
40 changes: 40 additions & 0 deletions TerrainFPS/Bullet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include <iostream>
// GL Includes
#include <glm/glm.hpp>

class Bullet
{
public:
glm::vec3 Position;
glm::vec3 Motion;
// Eular Angles
GLfloat Yaw;
GLfloat Pitch;

bool ToBeDestroyed = false;
const float MASS = 2.0f;
const float GRAVITY = -9.8f;

Bullet(glm::vec3 position, glm::vec3 motion, GLfloat yaw, GLfloat pitch) {
Position = position;
Motion = motion;
Yaw = yaw;
Pitch = pitch;
}

void updatePosition(float terrainHeight, float deltaTime) {
if (terrainHeight < Position.y) {
Motion.y += MASS * GRAVITY * deltaTime;
Position += Motion * deltaTime;
//std::cout << Position.y << std::endl;
}
else {
ToBeDestroyed = true;
std::cout << "Bullet Destroyed" << std::endl;
}
}

};

Loading

0 comments on commit 3955a70

Please sign in to comment.