Skip to content

Commit 2e32419

Browse files
committed
添加项目文件。
1 parent c372464 commit 2e32419

16 files changed

+1015
-0
lines changed

1.jpg

97.5 KB
Loading

Camera.h

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#pragma once
2+
3+
#include <GL/glew.h>
4+
#include <glm/glm.hpp>
5+
#include <glm/gtc/matrix_transform.hpp>
6+
7+
// Defines several possible options for camera movement. Used as abstraction to stay away from window-system specific input methods
8+
enum Camera_Movement {
9+
FORWARD,
10+
BACKWARD,
11+
LEFT,
12+
RIGHT
13+
};
14+
15+
// Default camera values
16+
const GLfloat YAW = 90.0f;
17+
const GLfloat PITCH = 90.0f;
18+
const GLfloat SPEED = 3.0f;
19+
const GLfloat SENSITIVTY = 0.5f;
20+
const GLfloat ZOOM = 45.0f;
21+
22+
23+
// An abstract camera class that processes input and calculates the corresponding Eular Angles, Vectors and Matrices for use in OpenGL
24+
class Camera
25+
{
26+
public:
27+
// Camera Attributes
28+
glm::vec3 Position;
29+
glm::vec3 Front;
30+
glm::vec3 Up;
31+
glm::vec3 Right;
32+
glm::vec3 WorldUp;
33+
// Eular Angles
34+
GLfloat Yaw;
35+
GLfloat Pitch;
36+
// Camera options
37+
GLfloat MovementSpeed;
38+
GLfloat MouseSensitivity;
39+
GLfloat Zoom;
40+
41+
// Constructor with vectors
42+
Camera(glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f), GLfloat yaw = YAW, GLfloat pitch = PITCH) : Front(glm::vec3(0.0f, 0.0f, -1.0f)), MovementSpeed(SPEED), MouseSensitivity(SENSITIVTY), Zoom(ZOOM)
43+
{
44+
this->Position = position;
45+
this->WorldUp = up;
46+
this->Yaw = yaw;
47+
this->Pitch = pitch;
48+
this->updateCameraVectors();
49+
}
50+
// Constructor with scalar values
51+
Camera(GLfloat posX, GLfloat posY, GLfloat posZ, GLfloat upX, GLfloat upY, GLfloat upZ, GLfloat yaw, GLfloat pitch) : Front(glm::vec3(0.0f, 0.0f, -1.0f)), MovementSpeed(SPEED), MouseSensitivity(SENSITIVTY), Zoom(ZOOM)
52+
{
53+
this->Position = glm::vec3(posX, posY, posZ);
54+
this->WorldUp = glm::vec3(upX, upY, upZ);
55+
this->Yaw = yaw;
56+
this->Pitch = pitch;
57+
this->updateCameraVectors();
58+
}
59+
60+
// Returns the view matrix calculated using Eular Angles and the LookAt Matrix
61+
glm::mat4 GetViewMatrix()
62+
{
63+
return glm::lookAt(this->Position, this->Position + this->Front, this->Up);
64+
}
65+
66+
// Processes input received from any keyboard-like input system. Accepts input parameter in the form of camera defined ENUM (to abstract it from windowing systems)
67+
void ProcessKeyboard(Camera_Movement direction, GLfloat deltaTime)
68+
{
69+
GLfloat velocity = this->MovementSpeed * deltaTime;
70+
if (direction == FORWARD)
71+
this->Position += this->Front * velocity;
72+
if (direction == BACKWARD)
73+
this->Position -= this->Front * velocity;
74+
if (direction == LEFT)
75+
this->Position -= this->Right * velocity;
76+
if (direction == RIGHT)
77+
this->Position += this->Right * velocity;
78+
}
79+
80+
81+
// Processes input received from a mouse input system. Expects the offset value in both the x and y direction.
82+
void ProcessMouseMovement(GLfloat xoffset, GLfloat yoffset, GLboolean constrainPitch = true)
83+
{
84+
xoffset *= this->MouseSensitivity;
85+
yoffset *= this->MouseSensitivity;
86+
87+
this->Yaw -= xoffset;
88+
this->Pitch -= yoffset;
89+
90+
// Make sure that when pitch is out of bounds, screen doesn't get flipped
91+
if (constrainPitch)
92+
{
93+
if (this->Pitch > 179.0f)
94+
this->Pitch = 179.0f;
95+
if (this->Pitch < 1.0f)
96+
this->Pitch = 1.0f;
97+
}
98+
cout << "yaw: " << Yaw << ", pitch: " << Pitch << endl;
99+
// Update Front, Right and Up Vectors using the updated Eular angles
100+
this->updateCameraVectors();
101+
}
102+
103+
// Processes input received from a mouse scroll-wheel event. Only requires input on the vertical wheel-axis
104+
void ProcessMouseScroll(GLfloat yoffset)
105+
{
106+
if (this->Zoom >= 1.0f && this->Zoom <= 45.0f)
107+
this->Zoom -= yoffset;
108+
if (this->Zoom <= 1.0f)
109+
this->Zoom = 1.0f;
110+
if (this->Zoom >= 45.0f)
111+
this->Zoom = 45.0f;
112+
}
113+
114+
private:
115+
// Calculates the front vector from the Camera's (updated) Eular Angles
116+
void updateCameraVectors()
117+
{
118+
// Calculate the new Front vector
119+
glm::vec3 front;
120+
front.x = -sin(glm::radians(this->Pitch)) * cos(glm::radians(this->Yaw));
121+
front.y = -cos(glm::radians(this->Pitch));
122+
front.z = -sin(glm::radians(this->Pitch)) * sin(glm::radians(this->Yaw));
123+
this->Front = glm::normalize(front);
124+
// Also re-calculate the Right and Up vector
125+
this->Right = glm::normalize(glm::cross(this->Front, glm::vec3(0.0f, 1.0f, 0.0f)));
126+
this->Up = glm::normalize(glm::cross(this->Right, this->Front));
127+
this->Position = -1.0f*glm::length(Position)*(this->Front);
128+
//this->Right = glm::normalize(glm::cross(this->Front, this->WorldUp)); // Normalize the vectors, because their length gets closer to 0 the more you look up or down which results in slower movement.
129+
//this->Up = glm::normalize(glm::cross(this->Right, this->Front));
130+
}
131+
};

OpenglTest.sln

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OpenglTest", "OpenglTest.vcxproj", "{BEE7F980-EA74-44D9-9061-1487BF387CD5}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{BEE7F980-EA74-44D9-9061-1487BF387CD5}.Debug|x64.ActiveCfg = Debug|x64
17+
{BEE7F980-EA74-44D9-9061-1487BF387CD5}.Debug|x64.Build.0 = Debug|x64
18+
{BEE7F980-EA74-44D9-9061-1487BF387CD5}.Debug|x86.ActiveCfg = Debug|Win32
19+
{BEE7F980-EA74-44D9-9061-1487BF387CD5}.Debug|x86.Build.0 = Debug|Win32
20+
{BEE7F980-EA74-44D9-9061-1487BF387CD5}.Release|x64.ActiveCfg = Release|x64
21+
{BEE7F980-EA74-44D9-9061-1487BF387CD5}.Release|x64.Build.0 = Release|x64
22+
{BEE7F980-EA74-44D9-9061-1487BF387CD5}.Release|x86.ActiveCfg = Release|Win32
23+
{BEE7F980-EA74-44D9-9061-1487BF387CD5}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal

OpenglTest.vcxproj

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<ProjectGuid>{BEE7F980-EA74-44D9-9061-1487BF387CD5}</ProjectGuid>
23+
<Keyword>Win32Proj</Keyword>
24+
<RootNamespace>OpenglTest</RootNamespace>
25+
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
26+
</PropertyGroup>
27+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
28+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
29+
<ConfigurationType>Application</ConfigurationType>
30+
<UseDebugLibraries>true</UseDebugLibraries>
31+
<PlatformToolset>v140</PlatformToolset>
32+
<CharacterSet>Unicode</CharacterSet>
33+
</PropertyGroup>
34+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
35+
<ConfigurationType>Application</ConfigurationType>
36+
<UseDebugLibraries>false</UseDebugLibraries>
37+
<PlatformToolset>v140</PlatformToolset>
38+
<WholeProgramOptimization>true</WholeProgramOptimization>
39+
<CharacterSet>Unicode</CharacterSet>
40+
</PropertyGroup>
41+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
42+
<ConfigurationType>Application</ConfigurationType>
43+
<UseDebugLibraries>true</UseDebugLibraries>
44+
<PlatformToolset>v140</PlatformToolset>
45+
<CharacterSet>Unicode</CharacterSet>
46+
</PropertyGroup>
47+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
48+
<ConfigurationType>Application</ConfigurationType>
49+
<UseDebugLibraries>false</UseDebugLibraries>
50+
<PlatformToolset>v140</PlatformToolset>
51+
<WholeProgramOptimization>true</WholeProgramOptimization>
52+
<CharacterSet>Unicode</CharacterSet>
53+
</PropertyGroup>
54+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
55+
<ImportGroup Label="ExtensionSettings">
56+
</ImportGroup>
57+
<ImportGroup Label="Shared">
58+
</ImportGroup>
59+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
60+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
61+
</ImportGroup>
62+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
63+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
64+
</ImportGroup>
65+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
66+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
67+
</ImportGroup>
68+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
69+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
70+
</ImportGroup>
71+
<PropertyGroup Label="UserMacros" />
72+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
73+
<LinkIncremental>true</LinkIncremental>
74+
<ReferencePath>$(ReferencePath)</ReferencePath>
75+
<LibraryPath>F:\OpenGL\build\x86\vc14;$(LibraryPath)</LibraryPath>
76+
<IncludePath>F:\OpenGL\include;$(IncludePath)</IncludePath>
77+
</PropertyGroup>
78+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
79+
<LinkIncremental>true</LinkIncremental>
80+
</PropertyGroup>
81+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
82+
<LinkIncremental>false</LinkIncremental>
83+
<IncludePath>F:\OpenGL\include;$(IncludePath)</IncludePath>
84+
<LibraryPath>F:\OpenGL\build\x86\vc14;$(LibraryPath)</LibraryPath>
85+
</PropertyGroup>
86+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
87+
<LinkIncremental>false</LinkIncremental>
88+
</PropertyGroup>
89+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
90+
<ClCompile>
91+
<PrecompiledHeader>
92+
</PrecompiledHeader>
93+
<WarningLevel>Level3</WarningLevel>
94+
<Optimization>Disabled</Optimization>
95+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
96+
</ClCompile>
97+
<Link>
98+
<SubSystem>Console</SubSystem>
99+
<GenerateDebugInformation>true</GenerateDebugInformation>
100+
<AdditionalDependencies>glfw3d.lib;glew32d.lib;OpenGL32.lib;SOILd.lib;%(AdditionalDependencies)</AdditionalDependencies>
101+
</Link>
102+
</ItemDefinitionGroup>
103+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
104+
<ClCompile>
105+
<PrecompiledHeader>
106+
</PrecompiledHeader>
107+
<WarningLevel>Level3</WarningLevel>
108+
<Optimization>Disabled</Optimization>
109+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
110+
</ClCompile>
111+
<Link>
112+
<SubSystem>Console</SubSystem>
113+
<GenerateDebugInformation>true</GenerateDebugInformation>
114+
</Link>
115+
</ItemDefinitionGroup>
116+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
117+
<ClCompile>
118+
<WarningLevel>Level3</WarningLevel>
119+
<PrecompiledHeader>
120+
</PrecompiledHeader>
121+
<Optimization>MaxSpeed</Optimization>
122+
<FunctionLevelLinking>true</FunctionLevelLinking>
123+
<IntrinsicFunctions>true</IntrinsicFunctions>
124+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
125+
</ClCompile>
126+
<Link>
127+
<SubSystem>Console</SubSystem>
128+
<GenerateDebugInformation>true</GenerateDebugInformation>
129+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
130+
<OptimizeReferences>true</OptimizeReferences>
131+
<AdditionalDependencies>glfw3.lib;glew32.lib;OpenGL32.lib;%(AdditionalDependencies)</AdditionalDependencies>
132+
</Link>
133+
</ItemDefinitionGroup>
134+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
135+
<ClCompile>
136+
<WarningLevel>Level3</WarningLevel>
137+
<PrecompiledHeader>
138+
</PrecompiledHeader>
139+
<Optimization>MaxSpeed</Optimization>
140+
<FunctionLevelLinking>true</FunctionLevelLinking>
141+
<IntrinsicFunctions>true</IntrinsicFunctions>
142+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
143+
</ClCompile>
144+
<Link>
145+
<SubSystem>Console</SubSystem>
146+
<GenerateDebugInformation>true</GenerateDebugInformation>
147+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
148+
<OptimizeReferences>true</OptimizeReferences>
149+
</Link>
150+
</ItemDefinitionGroup>
151+
<ItemGroup>
152+
<ClCompile Include="main.cpp" />
153+
</ItemGroup>
154+
<ItemGroup>
155+
<ClInclude Include="Camera.h" />
156+
<ClInclude Include="shader.h" />
157+
</ItemGroup>
158+
<ItemGroup>
159+
<None Include="lamp.frag" />
160+
<None Include="lamp.vs" />
161+
<None Include="lighting.frag" />
162+
<None Include="lighting.vs" />
163+
<None Include="shader.frag" />
164+
<None Include="shader.vs" />
165+
</ItemGroup>
166+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
167+
<ImportGroup Label="ExtensionTargets">
168+
</ImportGroup>
169+
</Project>

OpenglTest.vcxproj.filters

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="源文件">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="头文件">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="资源文件">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="main.cpp">
19+
<Filter>源文件</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ClInclude Include="shader.h">
24+
<Filter>头文件</Filter>
25+
</ClInclude>
26+
<ClInclude Include="Camera.h">
27+
<Filter>头文件</Filter>
28+
</ClInclude>
29+
</ItemGroup>
30+
<ItemGroup>
31+
<None Include="shader.frag">
32+
<Filter>资源文件</Filter>
33+
</None>
34+
<None Include="shader.vs">
35+
<Filter>资源文件</Filter>
36+
</None>
37+
<None Include="lamp.vs">
38+
<Filter>资源文件</Filter>
39+
</None>
40+
<None Include="lamp.frag">
41+
<Filter>资源文件</Filter>
42+
</None>
43+
<None Include="lighting.vs">
44+
<Filter>资源文件</Filter>
45+
</None>
46+
<None Include="lighting.frag">
47+
<Filter>资源文件</Filter>
48+
</None>
49+
</ItemGroup>
50+
</Project>

awesomeface.png

39.9 KB
Loading

container.jpg

181 KB
Loading

lamp.frag

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#version 330 core
2+
3+
out vec4 color;
4+
void main()
5+
{
6+
color = vec4(1.0f);
7+
};

0 commit comments

Comments
 (0)