Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • gamedev/fggl
  • onuralpsezer/fggl
2 results
Show changes
Showing
with 927 additions and 1 deletion
#version 330 core
// credit: https://learnopengl.com/Advanced-OpenGL/Geometry-Shader
out vec4 FragColor;
void main()
{
FragColor = vec4(1.0, 1.0, 0.0, 1.0);
}
#version 330 core
// credit: https://learnopengl.com/Advanced-OpenGL/Geometry-Shader
layout (triangles) in;
layout (line_strip, max_vertices = 6) out;
in VS_OUT {
vec3 normal;
} gs_in[];
const float MAGNITUDE = 0.4;
uniform mat4 projection;
void GenerateLine(int index)
{
gl_Position = projection * gl_in[index].gl_Position;
EmitVertex();
gl_Position = projection * (gl_in[index].gl_Position +
vec4(gs_in[index].normal, 0.0) * MAGNITUDE);
EmitVertex();
EndPrimitive();
}
void main()
{
GenerateLine(0); // first vertex normal
GenerateLine(1); // second vertex normal
GenerateLine(2); // third vertex normal
}
#version 330 core
// credit: https://learnopengl.com/Advanced-OpenGL/Geometry-Shader
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
out VS_OUT {
vec3 normal;
} vs_out;
uniform mat4 view;
uniform mat4 model;
void main()
{
gl_Position = view * model * vec4(aPos, 1.0);
mat3 normalMatrix = mat3(transpose(inverse(view * model)));
vs_out.normal = normalize(vec3(vec4(normalMatrix * aNormal, 0.0)));
}
#version 330 core
#extension GL_ARB_shading_language_include : require
// based on http://www.opengl-tutorial.org, WTFPL
// features lighting additions from https://learnopengl.com/, CC BY-NC 4.0
struct Material {
vec3 ambient;
vec3 diffuse;
vec3 specular;
float shininess;
};
uniform Material material;
uniform vec3 lightPos;
uniform vec3 objColour;
in vec3 normal;
in vec3 pos_ws;
in vec3 normal_cs;
in vec3 lightdir_cs;
in vec3 eyedir_cs;
out vec4 FragColor;
void main()
{
vec3 lightColour = vec3(1, 1, 1);
float lightPower = 200.0;
vec3 n = normalize( normal_cs );
vec3 l = normalize( lightdir_cs );
float distance = length( lightPos - pos_ws );
vec3 e = normalize( eyedir_cs );
vec3 r = reflect( -l, n );
float cosAlpha = clamp( dot(e, r), 0, 1);
float cosTheta = clamp( dot( n, l ), 0, 1 );
vec3 colour =
( material.ambient * vec3(0.1) ) +
( material.diffuse * vec3(0.5) * lightColour * lightPower * cosTheta / ( distance*distance ) ) +
( material.specular * lightColour * lightPower * pow( cosAlpha, material.shininess * 128 ) / (distance*distance) );
FragColor = vec4(colour, 1);
}
#version 330 core
// based on http://www.opengl-tutorial.org, WTFPL
uniform vec3 lightPos;
in vec3 normal;
in vec3 pos_ws;
in vec3 normal_cs;
in vec3 lightdir_cs;
in vec3 eyedir_cs;
out vec4 FragColor;
void main()
{
vec3 lightColour = vec3( 1.0, 1.0, 1.0 );
vec3 objColour = vec3(1.0f, 0.6f, 0.2f);
float lightPower = 50.0;
// material colours
vec3 matDiff = vec3(1.0, 0.6, 0.2 );
vec3 matAmb = vec3(0.1) * matDiff;
vec3 matSpec = vec3(0.3);
vec3 n = normalize( normal_cs );
vec3 l = normalize( lightdir_cs );
float distance = length( lightPos - pos_ws );
vec3 e = normalize( eyedir_cs );
vec3 r = reflect( -l, n );
float cosAlpha = clamp( dot(e, r), 0, 1);
float cosTheta = clamp( dot( n, l ), 0, 1 );
// vec3 colour =
// ( matAmb ) +
// ( matDiff * lightColour * lightPower * cosTheta / ( distance*distance ) ) +
// ( matSpec * lightColour * lightPower * pow( cosAlpha, 5 ) / (distance*distance) );
FragColor = vec4(normal, 1);
}
#version 330 core
// based on http://www.opengl-tutorial.org, WTFPL
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
uniform vec3 lightPos;
out vec3 normal;
out vec3 pos_ws;
out vec3 normal_cs;
out vec3 lightdir_cs;
out vec3 eyedir_cs;
void main()
{
gl_Position = projection * view * model * vec4(aPos, 1.0);
normal = aNormal;
// world space
pos_ws = ( model * vec4( aPos, 1 ) ).xyz;
// camera space
vec3 pos_cs = ( view * model * vec4(aPos, 1) ).xyz;
eyedir_cs = vec3(0, 0, 0) - pos_cs;
vec3 light_cs = ( view * vec4( lightPos, 1) ).xyz;
lightdir_cs = light_cs + eyedir_cs;
normal_cs = ( view * model * vec4( aNormal, 0 ) ).xyz;
}
/**
* OpenGL RedBook Shader.
* Examples 7.8, 7.9 and 7.10.
*
* Reflections are happening in camera space
*/
#version 330 core
in Vertex {
vec3 Position;
vec3 Normal;
vec3 Colour;
vec2 TexPos;
};
out vec4 FragColour;
const float constant = 1.0;
const float linear = 0.022;
const float quadratic = 0.0019;
float specPower = 0.5;
const float shininess = 8;
uniform sampler2D diffuseTexture;
uniform sampler2D specularTexture;
uniform mat4 MVMatrix;
uniform vec3 viewerPos_ws;
struct DirectionalLight {
vec3 direction;
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
struct Material {
vec3 emission;
vec3 ambient;
vec3 diffuse;
vec3 specular;
};
uniform DirectionalLight light;
uniform Material material;
const int hasPos = 0;
vec4 calcDirLight(DirectionalLight light, vec3 Normal, vec3 viewDir, vec4 specPx, vec4 diffPx) {
vec3 lightDir = normalize( ( vec4(light.direction, 1) * MVMatrix).xyz - Position.xyz );
vec4 ambient = 0.1 * vec4( light.ambient, 1);
vec3 reflectDir = reflect( -lightDir, Normal );
float spec = pow( max( dot(viewDir, reflectDir), 0.0), shininess);
vec4 specular = 1.0 * vec4( light.specular, 1) * specPower * (spec * specPx);
float diff = max( dot(Normal, lightDir), 0.0 );
vec4 diffuse = vec4(light.diffuse,1) * (diff * diffPx);
if ( hasPos == 1 ) {
vec3 lightPos = ( vec4(light.direction, 1) * MVMatrix).xyz;
float distance = length( lightPos - Position.xyz );
float att = 1.0 / (constant +
(linear * distance) +
(quadratic * (distance * distance)));
ambient *= att;
diffuse *= att;
specular *= att;
}
return (ambient + diffuse + specular);
}
void main() {
vec3 viewDir = normalize(-Position);
vec4 diffPx = vec4(material.diffuse, 1);
vec4 specPx = vec4(material.specular, 1);
if ( hasPos != 1) {
diffPx *= texture(diffuseTexture, TexPos);
specPx *= texture(specularTexture, TexPos);
}
FragColour = vec4(Colour, 1);
FragColour *= calcDirLight(light, Normal, viewDir, specPx, diffPx);
}
\ No newline at end of file
/**
* OpenGL RedBook Shader.
* Example 7.8
*/
#version 330 core
layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexNormal;
layout (location = 2) in vec3 VertexColour;
layout (location = 3) in vec2 VertexTex;
uniform mat4 MVPMatrix;
uniform mat4 MVMatrix;
uniform mat3 NormalMatrix;
out Vertex {
vec3 Position;
vec3 Normal;
vec3 Colour;
vec2 TexPos;
};
void main() {
Colour = VertexColour;
Normal = mat3(transpose(inverse(MVMatrix))) * VertexNormal;
TexPos = VertexTex;
Position = vec3(MVMatrix * vec4(VertexPosition, 1));
gl_Position = MVPMatrix * vec4(VertexPosition, 1);
}
\ No newline at end of file
/**
* OpenGL RedBook Shader.
* Examples 7.8, 7.9 and 7.10.
*/
#version 330 core
struct LightProperties {
bool isEnabled;
bool isLocal;
bool isSpot;
vec3 ambient;
vec3 colour;
vec3 position;
vec3 halfVector;
vec3 coneDirection;
float spotCosCustoff;
float spotExponent;
float constantAttenuation;
float linearAttenuation;
float quadraticAttenuation;
};
// example 7.9
struct MaterialProperties {
vec3 emission;
vec3 ambient;
vec3 diffuse;
vec3 specular;
float shininess;
};
const int MaxLights = 8;
uniform LightProperties lights[MaxLights];
const int MaxMaterials = 1;
uniform MaterialProperties materials[MaxMaterials];
uniform float Strength;
uniform vec3 EyeDirection;
in vec4 Position;
in vec3 Normal;
in vec4 Colour;
flat in int MatIndex;
out vec4 FragColour;
void main() {
vec3 scatteredLight = vec3(0.0);
vec3 reflectedLight = vec3(0.0);
for(int light = 0; light < MaxLights; ++light) {
if ( !lights[light].isEnabled ) continue;
vec3 halfVector;
vec3 lightDirection = lights[light].position;
float attenuation = 1.0;
float specular = 0;
if ( lights[light].isLocal ) {
lightDirection = lightDirection - vec3(Position);
float lightDistance = length(lightDirection);
lightDirection = lightDirection / lightDistance;
attenuation = 1.0 /
lights[light].constantAttenuation +
lights[light].linearAttenuation * lightDistance +
lights[light].quadraticAttenuation * lightDistance * lightDistance;
if ( lights[light].isSpot ) {
float spotCos = dot(lightDirection, -lights[light].coneDirection);
if ( spotCos < lights[light].spotCosCustoff )
attenuation = 0.0;
else
attenuation *= pow(spotCos, lights[light].spotExponent);
}
halfVector = normalize(lightDirection + EyeDirection);
specular = max(0.0, dot(Normal, halfVector));
} else {
//halfVector = lights[light].halfVector;
halfVector = reflect(-lightDirection, Normal);
specular = max(0.0, dot(EyeDirection, halfVector));
}
float diffuse = max(0.0, dot(Normal, lightDirection));
if (diffuse == 0.0)
specular = 0.0;
else
specular = pow(specular, materials[MatIndex].shininess) * Strength;
scatteredLight += lights[light].ambient * materials[MatIndex].ambient * attenuation +
lights[light].colour * materials[MatIndex].diffuse * diffuse * attenuation;
reflectedLight += lights[light].colour * materials[MatIndex].specular *
specular * attenuation;
}
vec3 rgb = min( materials[MatIndex].emission + Colour.rgb * scatteredLight + reflectedLight, vec3(1.0));
FragColour = vec4(rgb, 1.0);
}
\ No newline at end of file
/**
* OpenGL RedBook Shader.
* Example 7.8
*/
#version 330 core
uniform mat4 MVPMatrix;
uniform mat4 MVMatrix;
uniform mat3 NormalMatrix;
layout (location = 0) in vec3 VertexPosition;
layout (location = 1) in vec3 VertexNormal;
layout (location = 2) in vec3 VertexColour;
out vec4 Position;
out vec3 Normal;
out vec4 Colour;
out int matIndex;
void main() {
Colour = vec4(1.0, 1.0, 1.0, 1.0f);
Normal = NormalMatrix * VertexNormal;
Position = MVMatrix * vec4(VertexPosition, 1.0);
matIndex = 0;
gl_Position = MVPMatrix * vec4(VertexPosition, 1.0);
}
\ No newline at end of file
# non-free (non-CC) assets for testing
nonfree/
---
id: "com.fossgalaxy.games.demo"
name: "Demo Content Pack"
print("File has been loaded!")
-- when the scene loads, switch to topdown to show state integration
--switch_scene(state, "topdown");
\ No newline at end of file
---
prefabs:
- name: "rb_environment"
components:
gfx::material:
ambient: [0.0215, 0.1754, 0.0215]
diffuse: [1, 1, 1]
specular: [0.0633, 0.727811, 0.633]
shininess: 16
- name: "rb_wallX"
parent: "rb_environment"
components:
Transform:
StaticMesh:
pipeline: redbook/debug
shape_id: "mesh_rb_wall_x"
shape:
type: box
scale: [1.0, 5.0, 41]
phys::Body:
type: static
shape:
type: box
extents: [0.5, 2.5, 20.5]
# Wall Z shorter to avoid z-fighting
- name: "rb_wallZ"
parent: "rb_environment"
components:
Transform:
StaticMesh:
pipeline: redbook/debug
shape_id: "mesh_rb_wall_z"
shape:
type: box
scale: [39, 5, 1]
phys::Body:
type: static
shape:
type: box
extents: [ 19.5, 2.5, 0.5 ]
- name: "rb_floor"
parent: "rb_environment"
components:
Transform:
StaticMesh:
pipeline: redbook/debug
shape_id: "mesh_rb_floor"
shape:
type: box # we don't (currently) support planes...
scale: [39, 0.5, 39]
phys::Body:
type: static
shape:
type: box # we don't (currently) support planes...
extents: [19.5, 0.25, 19.5]
- name: rb_player
components:
Transform:
StaticMesh:
pipeline: redbook/debug
shape_id: "mesh_rb_player"
shape:
type: sphere
gfx::material:
ambient: [0.25, 0.25, 0.25]
diffuse: [0.4, 0.4, 0.4]
specular: [0.774597,0.774597,0.774597]
shininess: 16
phys::Body:
shape:
type: sphere
radius: 1
- name: rb_collectable
tags:
- "collectable"
components:
Transform:
StaticMesh:
pipeline: redbook/debug
shape_id: "mesh_rb_collect"
shape:
type: box
gfx::material:
ambient: [0.0215, 0.1754, 0.0215]
diffuse: [1, 1, 1]
specular: [0.0633, 0.727811, 0.633]
shininess: 16
phys::Body:
type: kinematic
shape:
type: box
- name: rb_light
components:
Transform:
gfx::phong::directional:
direction: [10, 5, 0]
scene:
- prefab: rb_wallX
components:
Transform:
origin: [20, 0, 0]
- prefab: rb_wallX
components:
Transform:
origin: [-20, 0, 0]
- prefab: rb_wallZ
components:
Transform:
origin: [0, 0, -20]
- prefab: rb_wallZ
components:
Transform:
origin: [0, 0, 20]
- prefab: rb_floor
components:
Transform:
origin: [0, -2.5, 0]
- prefab: rb_collectable
components:
Transform:
origin: [-5, -0.5, 12]
- prefab: rb_collectable
components:
Transform:
origin: [15, -0.5, 0.5]
- prefab: rb_collectable
components:
Transform:
origin: [6, -0.5, -15]
- prefab: rb_player
name: "player"
- prefab: rb_light
scripts:
- "rollball.lua"
\ No newline at end of file
#version 330 core
uniform sampler2D tex;
in vec3 colour;
in vec2 texPos;
out vec4 FragColor;
void main()
{
FragColor = vec4(colour.xyz, texture(tex, texPos).r);
}
#version 330 core
layout (location = 0) in vec2 aPos;
layout (location = 1) in vec3 aColour;
layout (location = 2) in vec2 aTexPos;
uniform mat4 projection;
out vec3 colour;
out vec2 texPos;
void main()
{
gl_Position = projection * vec4(aPos, 0.0f, 1.0f);
colour = aColour;
texPos = aTexPos;
}
---
floors:
ground:
visible: true
walls:
none:
visible: false
solid:
visible: true
\ No newline at end of file
---
prefabs:
- name: "wallX"
components:
Transform:
StaticMesh:
pipeline: redbook/debug
shape_id: td_wall_x
shape:
type: box
scale: [1.0, 5.0, 41]
gfx::material:
ambient: [0.25, 0.25, 0.25]
diffuse: [0.4, 0.4, 0.4]
specular: [0.774597,0.774597,0.774597]
shininess: 0.6
# phys::Body:
# type: static
# shape:
# type: box
# extents: [0.5, 2.5, 20.5]
# Wall Z shorter to avoid z-fighting
- name: "wallZ"
components:
Transform:
StaticMesh:
pipeline: redbook/debug
shape_id: td_wall_y
shape:
type: box
scale: [39, 5, 1]
gfx::material:
ambient: [0.25, 0.25, 0.25]
diffuse: [0.4, 0.4, 0.4]
specular: [0.774597,0.774597,0.774597]
shininess: 0.6
# phys::Body:
# type: static
# shape:
# type: box
# extents: [ 19.5, 2.5, 0.5 ]
- name: "floor"
components:
Transform:
StaticMesh:
pipeline: redbook/debug
shape_id: td_floor
shape:
type: box # we don't (currently) support planes...
scale: [39, 0.5, 39]
gfx::material:
ambient: [0.25, 0.25, 0.25]
diffuse: [0.4, 0.4, 0.4]
specular: [0.774597,0.774597,0.774597]
shininess: 0.6
# phys::Body:
# type: static
# shape:
# type: box # we don't (currently) support planes...
# extents: [19.5, 0.25, 19.5]
- name: player
components:
Transform:
StaticMesh:
pipeline: redbook/lighting
shape_id: td_player
shape:
type: sphere
gfx::material:
ambient: [0.25, 0.25, 0.25]
diffuse: [0.4, 0.4, 0.4]
specular: [0.774597,0.774597,0.774597]
shininess: 0.6
# phys::Body:
# shape:
# type: sphere
# radius: 1
- name: collectable
components:
Transform:
StaticMesh:
pipeline: redbook/lighting
shape_id: td_collect
shape:
type: box
gfx::material:
ambient: [0.0215, 0.1754, 0.0215]
diffuse: [1, 1, 1]
specular: [0.0633, 0.727811, 0.633]
shininess: 0.6
# phys::Body:
# type: kinematic
# shape:
# type: box
# phys::Callbacks:
# phys::Cache:
\ No newline at end of file
#version 330 core
layout (location = 0) in vec3 aPos;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
gl_Position = projection * view * model * vec4(aPos, 1.0f);
}
/*
* ${license.title}
* Copyright (C) 2022 ${license.owner}
* ${license.mailto}
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//
// Created by webpigeon on 22/04/22.
//
#include "GameScene.h"
#include "fggl/entity/loader/loader.hpp"
#include "fggl/mesh/components.hpp"
camera_type cam_mode = cam_free;
static void placeObject(fggl::entity::EntityManager& world, fggl::entity::EntityID floor, fggl::entity::EntityFactory* factory, fggl::util::GUID prototype, glm::vec3 targetPos) {
#ifndef NDEBUG
fggl::debug::trace("Creating object from prototype: {}", fggl::util::guid_to_string(prototype));
#endif
auto obj = factory->create(prototype, world);
auto& result = world.get<fggl::math::Transform>(obj);
int xPos = (int)targetPos.x;
int zPos = (int)targetPos.z * -1;
// figure out the floor height
auto heightMap = world.get<fggl::data::HeightMap>(floor);
targetPos.y = heightMap.getValue(xPos, zPos); // TODO should really be the gradient at the required point
result.origin( targetPos );
}
static void process_camera(fggl::entity::EntityManager& ecs, const fggl::input::Input& input) {
auto cameras = ecs.find<fggl::gfx::Camera>();
auto cam = cameras[0];
auto camTransform = ecs.get<fggl::math::Transform>(cam);
auto camComp = ecs.get<fggl::gfx::Camera>(cam);
const glm::vec3 dir = ( camTransform.origin() - camComp.target );
const glm::vec3 forward = glm::normalize( dir );
// scroll wheel
glm::vec3 motion(0.0f);
float delta = input.mouse.axis( fggl::input::MouseAxis::SCROLL_Y );
if ( (glm::length( dir ) < 25.0f && delta < 0.0f) || (glm::length( dir ) > 2.5f && delta > 0.0f) )
motion -= (forward * delta);
camTransform.origin( camTransform.origin() + motion );
if ( cam_mode == cam_arcball || input.mouse.down( fggl::input::MouseButton::MIDDLE ) ) {
fggl::input::process_arcball(ecs, input, cam);
} else if ( cam_mode == cam_free ) {
fggl::input::process_freecam(ecs, input, cam);
}
fggl::input::process_edgescroll( ecs, input, cam );
}
static void setupCamera(fggl::entity::EntityManager& world) {
auto prototype = world.create();
// setup camera position/transform
auto& transform = world.add<fggl::math::Transform>(prototype);
transform.origin(glm::vec3(10.0f, 3.0f, 10.0f));
// setup camera components
world.add<fggl::gfx::Camera>(prototype);
auto& cameraKeys = world.add<fggl::input::FreeCamKeys>(prototype);
cameraKeys.forward = glfwGetKeyScancode(GLFW_KEY_W);
cameraKeys.backward = glfwGetKeyScancode(GLFW_KEY_S);
cameraKeys.left = glfwGetKeyScancode(GLFW_KEY_A);
cameraKeys.right = glfwGetKeyScancode(GLFW_KEY_D);
cameraKeys.rotate_cw = glfwGetKeyScancode(GLFW_KEY_Q);
cameraKeys.rotate_ccw = glfwGetKeyScancode(GLFW_KEY_E);
}
static fggl::entity::EntityID setupTerrain(fggl::entity::EntityManager& world) {
fggl::entity::EntityID terrain;
{
terrain = world.create();
auto& camTf = world.add<fggl::math::Transform>(terrain);
camTf.origin( glm::vec3(-128.0f, 0.0f, 128.0f) );
//auto terrainData = m_world.get<fggl::data::HeightMap>(terrain);
fggl::data::HeightMap terrainData{};
terrainData.clear();
const siv::PerlinNoise::seed_type seed = 123456U;
const siv::PerlinNoise perlin{ seed };
for (std::size_t z = 0; z < fggl::data::heightMaxZ; ++z) {
for (std::size_t x = 0; x < fggl::data::heightMaxX; ++x) {
const double noise = perlin.octave2D_11( (x * 0.01), (z * 0.01) , 4) * 10.f;
terrainData.setValue(x, z, (float)noise);
}
}
world.add<fggl::data::HeightMap>(terrain, terrainData);
}
return terrain;
}
static fggl::entity::EntityID setup_environment(fggl::entity::EntityManager& world) {
setupCamera(world);
return setupTerrain(world);
}
static auto BUNKER_PROTOTYPE = "bunker"_fid;
static void setupBunkerPrototype(fggl::entity::EntityFactory* factory) {
{
auto bunkerSpec = fggl::entity::EntitySpec{};
bunkerSpec.addComp(fggl::math::Transform::guid, {});
// mesh
int nSections = 2;
fggl::mesh::MultiMesh3D mesh;
for (int j=-(nSections/2); j<=nSections/2; j++) {
const auto shapeOffset = glm::vec3( 0.0f, 0.5f, (float)j * 1.0f );
const auto cubeMat = glm::translate( fggl::math::mat4( 1.0f ) , shapeOffset );
const auto leftSlope = fggl::math::modelMatrix(
glm::vec3(-1.0f, 0.0f, 0.0f) + shapeOffset,
glm::vec3( 0.0f, -fggl::math::HALF_PI, 0.0f) );
const auto rightSlope = fggl::math::modelMatrix(
glm::vec3( 1.0f, 0.0f, 0.0f) + shapeOffset,
glm::vec3( 0.0f, fggl::math::HALF_PI, 0.0f) );
fggl::data::make_cube( mesh.generate(), cubeMat);
fggl::data::make_slope( mesh.generate(), leftSlope );
fggl::data::make_slope( mesh.generate(), rightSlope );
}
//mesh.removeDups();
// generate mesh component data
// FIXME: find a better way to do this, avoid re-uploading the whole mesh.
fggl::entity::ComponentSpec procMesh{};
procMesh.set<std::string>("pipeline", "redbook/debug");
YAML::Node modelNode;
for (auto& submesh : mesh.meshes) {
YAML::Node vertexData;
for (auto& vertex : submesh.data) {
YAML::Node vertexNode;
vertexNode["position"] = vertex.position;
vertexNode["normal"] = vertex.normal;
vertexNode["colour"] = vertex.colour;
vertexNode["texPos"] = vertex.texPos;
vertexData.push_back(vertexNode);
}
YAML::Node indexData;
for (auto& index : submesh.indices) {
indexData.push_back(index);
}
YAML::Node meshNode;
meshNode["vertex"] = vertexData;
meshNode["index"] = indexData;
modelNode.push_back( meshNode );
}
procMesh.set("model", modelNode);
bunkerSpec.addComp(fggl::mesh::StaticMultiMesh3D::guid, procMesh);
factory->define(BUNKER_PROTOTYPE, bunkerSpec);
}
}
void GameScene::setup() {
m_canvas.size( fggl::math::vec2(0,0), fggl::math::vec2(100, 100));
auto* entityFactory = m_owner.service<fggl::entity::EntityFactory>();
auto terrain = setup_environment(world());
setupBunkerPrototype(entityFactory);
// create building prototype
int nCubes = 3;
for ( int i=0; i<nCubes; i++ ) {
glm::vec3 location;
location.x = i * 6.f + 1.0f;
location.z = -5.0f + 1.0f;
placeObject(world(), terrain, entityFactory, BUNKER_PROTOTYPE, location);
}
}
void GameScene::update(float dt) {
Game::update(dt);
process_camera(world(), input());
}
void GameScene::render(fggl::gfx::Graphics &gfx) {
Game::render(gfx);
const fggl::math::vec2 panelSize { 250.0F, 250.0F };
const auto canvasY = gfx.canvasBounds().bottom - panelSize.y;
m_canvas.size( {0.0F, canvasY}, panelSize);
// now the 2D scene
fggl::gfx::Paint paint;
m_canvas.render(paint);
gfx.draw2D(paint);
}
\ No newline at end of file