fix input handler and add light cubes
This commit is contained in:
parent
f4aea18121
commit
0792cb6e92
|
@ -4,7 +4,7 @@ OTHER_LIBS = -lm
|
||||||
|
|
||||||
ALL_LIBS = $(GLEW_LIBS) $(GLFW_LIBS) $(OTHER_LIBS)
|
ALL_LIBS = $(GLEW_LIBS) $(GLFW_LIBS) $(OTHER_LIBS)
|
||||||
|
|
||||||
OBJ = matrixMath.o transformation.o wavefrontobj.o sceneGraph.o objectHandler.o shader.o
|
OBJ = matrixMath.o transformation.o wavefrontobj.o sceneGraph.o objectHandler.o shader.o inputHandler.o
|
||||||
SHADERS = fragmentShader.c vertexShader.c skyboxFragmentShader.c skyboxVertexShader.c
|
SHADERS = fragmentShader.c vertexShader.c skyboxFragmentShader.c skyboxVertexShader.c
|
||||||
|
|
||||||
cg1.out: test.out main.o $(OBJ) $(SHADERS)
|
cg1.out: test.out main.o $(OBJ) $(SHADERS)
|
||||||
|
@ -17,7 +17,7 @@ test.out: test.o $(OBJ)
|
||||||
%Shader.c: %Shader.glsl
|
%Shader.c: %Shader.glsl
|
||||||
xxd -i $? | tac | sed "3s/$$/, 0x00/" | tac > $@
|
xxd -i $? | tac | sed "3s/$$/, 0x00/" | tac > $@
|
||||||
|
|
||||||
main.o: $(SHADERS) matrixMath.h transformation.h wavefrontobj.h sceneGraph.h objectHandler.h shader.h
|
main.o: $(SHADERS) matrixMath.h transformation.h wavefrontobj.h sceneGraph.h objectHandler.h shader.h inputHandler.h
|
||||||
|
|
||||||
test.o: matrixMath.h transformation.h wavefrontobj.h
|
test.o: matrixMath.h transformation.h wavefrontobj.h
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
#include "inputHandler.h"
|
#include "inputHandler.h"
|
||||||
|
|
||||||
|
bool exitRequested = false;
|
||||||
|
GLFWwindow* window;
|
||||||
|
const GLfloat pi = 3.14159f;
|
||||||
|
vec3 origin = {0.0f, 0.0f, 0.0f};
|
||||||
|
vec3 cameraPosition = {0.0f, 2.0f, 1.0f};
|
||||||
|
vec3 objectPosition = {0.0f, 0.0f, 0.0f};
|
||||||
|
vec3 cameraTravelPosition = {0.3f, 0.3f, 0.3f};
|
||||||
|
bool cameraTraveling = false;
|
||||||
|
GLfloat radius = 1.0f;
|
||||||
|
SceneNode* rootNode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves the camera in a somewhat smooth motion.
|
* Moves the camera in a somewhat smooth motion.
|
||||||
*/
|
*/
|
||||||
|
@ -67,6 +78,7 @@ void handleInputs(double deltaTime)
|
||||||
vec3 delta;
|
vec3 delta;
|
||||||
|
|
||||||
vec3Subtract(&delta, &origin, &cameraPosition);
|
vec3Subtract(&delta, &origin, &cameraPosition);
|
||||||
|
delta.y = 0;
|
||||||
vec3Normalise(&delta, &delta);
|
vec3Normalise(&delta, &delta);
|
||||||
vec3Multiply(&delta, &delta, -10);
|
vec3Multiply(&delta, &delta, -10);
|
||||||
vec3Multiply(&delta, &delta, deltaTime);
|
vec3Multiply(&delta, &delta, deltaTime);
|
||||||
|
@ -77,6 +89,7 @@ void handleInputs(double deltaTime)
|
||||||
{
|
{
|
||||||
vec3 delta;
|
vec3 delta;
|
||||||
vec3Subtract(&delta, &origin, &cameraPosition);
|
vec3Subtract(&delta, &origin, &cameraPosition);
|
||||||
|
delta.y = 0;
|
||||||
if (vec3Length(&delta) > 0.1)
|
if (vec3Length(&delta) > 0.1)
|
||||||
{
|
{
|
||||||
vec3Normalise(&delta, &delta);
|
vec3Normalise(&delta, &delta);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef INPUTHANDLER_H
|
#ifndef INPUTHANDLER_H
|
||||||
#define INPUTHANDLER_H
|
#define INPUTHANDLER_H
|
||||||
|
|
||||||
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include "matrixMath.h"
|
#include "matrixMath.h"
|
||||||
#include "sceneGraph.h"
|
#include "sceneGraph.h"
|
||||||
|
|
36
src/main.c
36
src/main.c
|
@ -19,7 +19,7 @@
|
||||||
#include "wavefrontobj.h"
|
#include "wavefrontobj.h"
|
||||||
#include "sceneGraph.h"
|
#include "sceneGraph.h"
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "inputHandler.c"
|
#include "inputHandler.h"
|
||||||
|
|
||||||
GLuint program;
|
GLuint program;
|
||||||
GLuint skyboxProgram;
|
GLuint skyboxProgram;
|
||||||
|
@ -37,10 +37,6 @@ GLuint skyboxTexture;
|
||||||
|
|
||||||
int flipFlag = 1;
|
int flipFlag = 1;
|
||||||
|
|
||||||
bool exitRequested = false;
|
|
||||||
|
|
||||||
GLFWwindow* window;
|
|
||||||
|
|
||||||
GLfloat aspectRatio = 1.0f;
|
GLfloat aspectRatio = 1.0f;
|
||||||
|
|
||||||
double timeBetweenUpdates = 0.2f;
|
double timeBetweenUpdates = 0.2f;
|
||||||
|
@ -49,21 +45,10 @@ double timeSinceUpdate = 0.0f;
|
||||||
int framesSinceUpdate = 0;
|
int framesSinceUpdate = 0;
|
||||||
|
|
||||||
GLfloat step = 0.0f;
|
GLfloat step = 0.0f;
|
||||||
const GLfloat pi = 3.14159f;
|
|
||||||
|
|
||||||
vec3 origin = {0.0f, 0.0f, 0.0f};
|
|
||||||
vec3 cameraPosition = {0.0f, 2.0f, 1.0f};
|
|
||||||
vec3 objectPosition = {0.0f, 0.0f, 0.0f};
|
|
||||||
|
|
||||||
vec3 cameraTravelPosition = {0.3f, 0.3f, 0.3f};
|
|
||||||
bool cameraTraveling = false;
|
|
||||||
|
|
||||||
GLfloat radius = 1.0f;
|
|
||||||
mat4 viewingTransformation;
|
mat4 viewingTransformation;
|
||||||
mat4 projection;
|
mat4 projection;
|
||||||
|
|
||||||
// Define a global scene graph root node
|
|
||||||
SceneNode* rootNode;
|
|
||||||
|
|
||||||
void renderNode(SceneNode* node) {
|
void renderNode(SceneNode* node) {
|
||||||
assert(node != NULL);
|
assert(node != NULL);
|
||||||
|
@ -315,6 +300,25 @@ void draw(void) {
|
||||||
glUniform4f(glGetUniformLocation(program, "ambientLight"), 0.05f, 0.05f, 0.05f, 1.0f);
|
glUniform4f(glGetUniformLocation(program, "ambientLight"), 0.05f, 0.05f, 0.05f, 1.0f);
|
||||||
|
|
||||||
vec4 lightPosition = {cos(stepi) * 5.0f, 5.0f, sin(stepi) * 5.0f, 1.0f};
|
vec4 lightPosition = {cos(stepi) * 5.0f, 5.0f, sin(stepi) * 5.0f, 1.0f};
|
||||||
|
|
||||||
|
// move cubes to light positions
|
||||||
|
mat4 transformLights;
|
||||||
|
vec3 lightScale = {0.1, 0.1, 0.1};
|
||||||
|
scaling(&transformLights, &lightScale);
|
||||||
|
translate(&transformLights, &transformLights, (vec3*)&lightPosition);
|
||||||
|
|
||||||
|
SceneNode* light = findNodeByName("Light1", rootNode);
|
||||||
|
light->transformation = transformLights;
|
||||||
|
updateSceneNode(light, &rootNode->worldTransformation);
|
||||||
|
|
||||||
|
transformLights.m03 = - transformLights.m03;
|
||||||
|
transformLights.m23 = - transformLights.m23;
|
||||||
|
|
||||||
|
light = findNodeByName("Light2", rootNode);
|
||||||
|
light->transformation = transformLights;
|
||||||
|
updateSceneNode(light, &rootNode->worldTransformation);
|
||||||
|
|
||||||
|
// apply viewing transformation and pass light positions to shader
|
||||||
multiplyAny((GLfloat*)&lightPosition, (GLfloat*)&viewingTransformation, (GLfloat*)&lightPosition, 4, 4, 1);
|
multiplyAny((GLfloat*)&lightPosition, (GLfloat*)&viewingTransformation, (GLfloat*)&lightPosition, 4, 4, 1);
|
||||||
|
|
||||||
glUniform3f(glGetUniformLocation(program, "lightPositions[0]"), lightPosition.x, lightPosition.y, lightPosition.z);
|
glUniform3f(glGetUniformLocation(program, "lightPositions[0]"), lightPosition.x, lightPosition.y, lightPosition.z);
|
||||||
|
|
Loading…
Reference in New Issue