Added an environment to the example game; AssetPack changes
This commit is contained in:
parent
a1fe7c3c1a
commit
be06ee2d20
13
Game/assets/example/models/env.mtl
Normal file
13
Game/assets/example/models/env.mtl
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Blender MTL File: 'None'
|
||||||
|
# Material Count: 1
|
||||||
|
|
||||||
|
newmtl grass
|
||||||
|
Ns 225.000000
|
||||||
|
Ka 1.000000 1.000000 1.000000
|
||||||
|
Kd 0.800000 0.800000 0.800000
|
||||||
|
Ks 0.000000 0.000000 0.000000
|
||||||
|
Ke 0.000000 0.000000 0.000000
|
||||||
|
Ni 1.450000
|
||||||
|
d 1.000000
|
||||||
|
illum 1
|
||||||
|
map_Kd grass.jpg
|
196255
Game/assets/example/models/env.obj
Normal file
196255
Game/assets/example/models/env.obj
Normal file
File diff suppressed because it is too large
Load Diff
BIN
Game/assets/example/textures/grass.jpg
Normal file
BIN
Game/assets/example/textures/grass.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 275 KiB |
@ -5,10 +5,11 @@ void MainState::onEnter() {
|
|||||||
currCamType = nf::Camera::Type::FIRST_PERSON;
|
currCamType = nf::Camera::Type::FIRST_PERSON;
|
||||||
camera->setType(currCamType);
|
camera->setType(currCamType);
|
||||||
ap.load("example.nfpack");
|
ap.load("example.nfpack");
|
||||||
test.create(ap["2mats.obj"], nf::Entity::Type::DYNAMIC);
|
test.create(ap.get("2mats.obj"), nf::Entity::Type::DYNAMIC);
|
||||||
test.setPosition(nf::Vec3(0.0, 1.5, -5.0));
|
test.setPosition(nf::Vec3(0.0, 1.5, -5.0));
|
||||||
plane.create(nf::BaseAssets::plane);
|
plane.create(ap.get("env.obj"), nf::Entity::Type::ENVIRONMENT);
|
||||||
plane.setScale(20.0);
|
plane.setScale(20.0);
|
||||||
|
plane.setPosition(0.0, -20.0, 0.0);
|
||||||
text.create("", nf::Vec2(0.1, 0.025), nf::Vec3(0.8));
|
text.create("", nf::Vec2(0.1, 0.025), nf::Vec3(0.8));
|
||||||
text.centered(true);
|
text.centered(true);
|
||||||
gravText.create("", nf::Vec2(0.025, 0.2), nf::Vec3(0.8), 1.0f, 0.5f);
|
gravText.create("", nf::Vec2(0.025, 0.2), nf::Vec3(0.8), 1.0f, 0.5f);
|
||||||
@ -20,9 +21,9 @@ void MainState::onEnter() {
|
|||||||
light3.create(nf::Vec3(10.0, 20.0, 10.0), nf::Vec3(1.0, 1.0, 1.0));
|
light3.create(nf::Vec3(10.0, 20.0, 10.0), nf::Vec3(1.0, 1.0, 1.0));
|
||||||
cm.create(nf::BaseAssets::cubemap);
|
cm.create(nf::BaseAssets::cubemap);
|
||||||
|
|
||||||
sound.create(ap["sound.wav"]);
|
sound.create(ap.get("sound.wav"));
|
||||||
sound.setEntity(test);
|
sound.setEntity(test);
|
||||||
sound2.create(ap["test.ogg"]);
|
sound2.create(ap.get("test.ogg"));
|
||||||
sound2.setVolume(3.0);
|
sound2.setVolume(3.0);
|
||||||
sound2.setEntity(test);
|
sound2.setEntity(test);
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ void MainState::onEnter() {
|
|||||||
for (int y = 0; y < 5; y++) {
|
for (int y = 0; y < 5; y++) {
|
||||||
for (int z = 0; z < 5; z++) {
|
for (int z = 0; z < 5; z++) {
|
||||||
entities.push_back(new nf::Entity);
|
entities.push_back(new nf::Entity);
|
||||||
entities.back()->create(ap["2mats.obj"], nf::Entity::Type::DYNAMIC);
|
entities.back()->create(ap.get("2mats.obj"), nf::Entity::Type::DYNAMIC);
|
||||||
entities.back()->setPosition(nf::Vec3(5.0 + x * 2.05, 1.0 + y * 2.05, -5.0 + z * 2.05));
|
entities.back()->setPosition(nf::Vec3(5.0 + x * 2.05, 1.0 + y * 2.05, -5.0 + z * 2.05));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,8 +40,8 @@ void MainState::onEnter() {
|
|||||||
grav = 2.0f;
|
grav = 2.0f;
|
||||||
setGravity(grav);
|
setGravity(grav);
|
||||||
|
|
||||||
camera->setPosition(-20.0, 5.0, 0.0);
|
camera->setPosition(-20.0, 15.0, 0.0);
|
||||||
camera->setRotation(85.0, 0.0);
|
camera->setRotation(85.0, -30.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainState::update(float deltaTime) {
|
void MainState::update(float deltaTime) {
|
||||||
|
@ -250,13 +250,21 @@ namespace nf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Asset* AssetPack::operator[](const char* in) {
|
Asset* AssetPack::get(const char* in) {
|
||||||
if (m_assets.find(in) == m_assets.end())
|
if (m_assets.find(in) == m_assets.end())
|
||||||
Error("Could not find asset \"" + (std::string)in + (std::string)"\" in asset pack!");
|
Error("Could not find asset \"" + (std::string)in + (std::string)"\" in asset pack!");
|
||||||
return m_assets[in];
|
return m_assets[in];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Asset* AssetPack::get(std::string& in) {
|
||||||
|
return get(in.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
Asset* AssetPack::operator[](const char* in) {
|
||||||
|
return get(in);
|
||||||
|
}
|
||||||
Asset* AssetPack::operator[](std::string& in) {
|
Asset* AssetPack::operator[](std::string& in) {
|
||||||
return operator[](in.c_str());
|
return get(in.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetPack::destroy() {
|
void AssetPack::destroy() {
|
||||||
|
@ -71,6 +71,11 @@ namespace nf {
|
|||||||
usingMat = matName;
|
usingMat = matName;
|
||||||
}
|
}
|
||||||
else if (std::strcmp(&firstWord[0], "f") == 0) {
|
else if (std::strcmp(&firstWord[0], "f") == 0) {
|
||||||
|
if (!tcPresent)
|
||||||
|
Error("No texture coordinates found in model!");
|
||||||
|
if (!vnPresent)
|
||||||
|
Error("No normals found in model!");
|
||||||
|
|
||||||
unsigned int vertexIndex[3], uvIndex[3], vnIndex[3];
|
unsigned int vertexIndex[3], uvIndex[3], vnIndex[3];
|
||||||
char temp;
|
char temp;
|
||||||
ss >> vertexIndex[0] >> temp >> uvIndex[0] >> temp >> vnIndex[0] >> vertexIndex[1] >> temp >> uvIndex[1] >> temp >> vnIndex[1] >> vertexIndex[2] >> temp >> uvIndex[2] >> temp >> vnIndex[2];
|
ss >> vertexIndex[0] >> temp >> uvIndex[0] >> temp >> vnIndex[0] >> vertexIndex[1] >> temp >> uvIndex[1] >> temp >> vnIndex[1] >> vertexIndex[2] >> temp >> uvIndex[2] >> temp >> vnIndex[2];
|
||||||
@ -88,11 +93,6 @@ namespace nf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tcPresent)
|
|
||||||
Error("No texture coordinates found in model!");
|
|
||||||
if (!vnPresent)
|
|
||||||
Error("No normals found in model!");
|
|
||||||
|
|
||||||
for (auto& m : mats) {
|
for (auto& m : mats) {
|
||||||
std::string curr = m.first;
|
std::string curr = m.first;
|
||||||
for (unsigned int i = 0; i < mats[curr]->vbIndices.size(); i++) {
|
for (unsigned int i = 0; i < mats[curr]->vbIndices.size(); i++) {
|
||||||
|
@ -372,42 +372,42 @@ namespace nf {
|
|||||||
|
|
||||||
void Renderer::loadBaseAssets() {
|
void Renderer::loadBaseAssets() {
|
||||||
m_baseAP.load("base.nfpack");
|
m_baseAP.load("base.nfpack");
|
||||||
const char* gBufferVertex = m_baseAP["gBufferVertex.shader"]->data;
|
const char* gBufferVertex = m_baseAP.get("gBufferVertex.shader")->data;
|
||||||
const char* gBufferFragment = m_baseAP["gBufferFragment.shader"]->data;
|
const char* gBufferFragment = m_baseAP.get("gBufferFragment.shader")->data;
|
||||||
m_gBufferShader = new Shader(gBufferVertex, gBufferFragment);
|
m_gBufferShader = new Shader(gBufferVertex, gBufferFragment);
|
||||||
const char* lightingVertex = m_baseAP["lightingVertex.shader"]->data;
|
const char* lightingVertex = m_baseAP.get("lightingVertex.shader")->data;
|
||||||
const char* lightingFragment = m_baseAP["lightingFragment.shader"]->data;
|
const char* lightingFragment = m_baseAP.get("lightingFragment.shader")->data;
|
||||||
m_lightingShader = new Shader(lightingVertex, lightingFragment);
|
m_lightingShader = new Shader(lightingVertex, lightingFragment);
|
||||||
const char* textVertex = m_baseAP["textVertex.shader"]->data;
|
const char* textVertex = m_baseAP.get("textVertex.shader")->data;
|
||||||
const char* textFragment = m_baseAP["textFragment.shader"]->data;
|
const char* textFragment = m_baseAP.get("textFragment.shader")->data;
|
||||||
m_textShader = new Shader(textVertex, textFragment);
|
m_textShader = new Shader(textVertex, textFragment);
|
||||||
const char* uiTextureVertex = m_baseAP["uiTextureVertex.shader"]->data;
|
const char* uiTextureVertex = m_baseAP.get("uiTextureVertex.shader")->data;
|
||||||
const char* uiTextureFragment = m_baseAP["uiTextureFragment.shader"]->data;
|
const char* uiTextureFragment = m_baseAP.get("uiTextureFragment.shader")->data;
|
||||||
m_uiTextureShader = new Shader(uiTextureVertex, uiTextureFragment);
|
m_uiTextureShader = new Shader(uiTextureVertex, uiTextureFragment);
|
||||||
const char* cubemapVertex = m_baseAP["cubemapVertex.shader"]->data;
|
const char* cubemapVertex = m_baseAP.get("cubemapVertex.shader")->data;
|
||||||
const char* cubemapFragment = m_baseAP["cubemapFragment.shader"]->data;
|
const char* cubemapFragment = m_baseAP.get("cubemapFragment.shader")->data;
|
||||||
m_cubemapShader = new Shader(cubemapVertex, cubemapFragment);
|
m_cubemapShader = new Shader(cubemapVertex, cubemapFragment);
|
||||||
const char* fadeVertex = m_baseAP["fadeVertex.shader"]->data;
|
const char* fadeVertex = m_baseAP.get("fadeVertex.shader")->data;
|
||||||
const char* fadeFragment = m_baseAP["fadeFragment.shader"]->data;
|
const char* fadeFragment = m_baseAP.get("fadeFragment.shader")->data;
|
||||||
m_fadeShader = new Shader(fadeVertex, fadeFragment);
|
m_fadeShader = new Shader(fadeVertex, fadeFragment);
|
||||||
const char* directionalShadowVertex = m_baseAP["directionalShadowVertex.shader"]->data;
|
const char* directionalShadowVertex = m_baseAP.get("directionalShadowVertex.shader")->data;
|
||||||
const char* directionalShadowFragment = m_baseAP["directionalShadowFragment.shader"]->data;
|
const char* directionalShadowFragment = m_baseAP.get("directionalShadowFragment.shader")->data;
|
||||||
m_directionalShadowShader = new Shader(directionalShadowVertex, directionalShadowFragment);
|
m_directionalShadowShader = new Shader(directionalShadowVertex, directionalShadowFragment);
|
||||||
const char* pointShadowVertex = m_baseAP["pointShadowVertex.shader"]->data;
|
const char* pointShadowVertex = m_baseAP.get("pointShadowVertex.shader")->data;
|
||||||
const char* pointShadowGeometry = m_baseAP["pointShadowGeometry.shader"]->data;
|
const char* pointShadowGeometry = m_baseAP.get("pointShadowGeometry.shader")->data;
|
||||||
const char* pointShadowFragment = m_baseAP["pointShadowFragment.shader"]->data;
|
const char* pointShadowFragment = m_baseAP.get("pointShadowFragment.shader")->data;
|
||||||
m_pointShadowShader = new Shader(pointShadowVertex, pointShadowFragment, pointShadowGeometry);
|
m_pointShadowShader = new Shader(pointShadowVertex, pointShadowFragment, pointShadowGeometry);
|
||||||
|
|
||||||
BaseAssets::cube = (AModel*)m_baseAP["cube.obj"];
|
BaseAssets::cube = (AModel*)m_baseAP.get("cube.obj");
|
||||||
BaseAssets::plane = (AModel*)m_baseAP["plane.obj"];
|
BaseAssets::plane = (AModel*)m_baseAP.get("plane.obj");
|
||||||
BaseAssets::sphere = (AModel*)m_baseAP["sphere.obj"];
|
BaseAssets::sphere = (AModel*)m_baseAP.get("sphere.obj");
|
||||||
BaseAssets::cone = (AModel*)m_baseAP["cone.obj"];
|
BaseAssets::cone = (AModel*)m_baseAP.get("cone.obj");
|
||||||
BaseAssets::cylinder = (AModel*)m_baseAP["cylinder.obj"];
|
BaseAssets::cylinder = (AModel*)m_baseAP.get("cylinder.obj");
|
||||||
BaseAssets::torus = (AModel*)m_baseAP["torus.obj"];
|
BaseAssets::torus = (AModel*)m_baseAP.get("torus.obj");
|
||||||
BaseAssets::logo = (ATexture*)m_baseAP["logo.png"];
|
BaseAssets::logo = (ATexture*)m_baseAP.get("logo.png");
|
||||||
BaseAssets::cubemap = (ACubemap*)m_baseAP["default.cm"];
|
BaseAssets::cubemap = (ACubemap*)m_baseAP.get("default.cm");
|
||||||
BaseAssets::font = (AFont*)m_baseAP["default.ttf"];
|
BaseAssets::font = (AFont*)m_baseAP.get("default.ttf");
|
||||||
BaseAssets::button = (AButton*)m_baseAP["default.button"];
|
BaseAssets::button = (AButton*)m_baseAP.get("default.button");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::createShadowMaps() {
|
void Renderer::createShadowMaps() {
|
||||||
|
@ -77,6 +77,8 @@ namespace nf {
|
|||||||
AssetPack();
|
AssetPack();
|
||||||
|
|
||||||
void load(const char* packName);
|
void load(const char* packName);
|
||||||
|
Asset* get(const char* in);
|
||||||
|
Asset* get(std::string& in);
|
||||||
Asset* operator[](const char* in);
|
Asset* operator[](const char* in);
|
||||||
Asset* operator[](std::string& in);
|
Asset* operator[](std::string& in);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user