This commit is contained in:
Anselme 2017-09-05 18:35:39 +02:00
commit b92fa1b556
12 changed files with 146 additions and 13 deletions

View File

@ -194,6 +194,7 @@ void Engine::enablePhysicsDebug()
{
m_physicsDebugNode = new PhysicsDebugNode();
getScene()->addToIndex(m_physicsDebugNode);
getScene()->registerMeshType(m_physicsDebugNode->getGeometryNode()->mesh->getFlags());
getScene()->getPhysics()->setDebugDrawer(m_physicsDebugNode);
getScene()->getPhysics()->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe);
}

View File

@ -28,13 +28,13 @@ btRigidBody* MeshNode::buildStaticCollider()
btIndexedMesh *bulletMesh = new btIndexedMesh();
Mesh *m = m_geometry.mesh;
// vertices
bulletMesh->m_numVertices = m->positions3D.size();
bulletMesh->m_vertexBase = (unsigned char*)(m->positions3D.data());
bulletMesh->m_numVertices = m->m_positions3D.size();
bulletMesh->m_vertexBase = (unsigned char*)(m->m_positions3D.data());
bulletMesh->m_vertexStride = sizeof(glm::vec3);
bulletMesh->m_vertexType = PHY_FLOAT;
// indices
bulletMesh->m_numTriangles = m->indices.size()/3;
bulletMesh->m_triangleIndexBase = (unsigned char*)(m->indices.data());
bulletMesh->m_numTriangles = m->m_indices.size()/3;
bulletMesh->m_triangleIndexBase = (unsigned char*)(m->m_indices.data());
bulletMesh->m_triangleIndexStride = 3*sizeof(GLuint);
bulletMesh->m_indexType = PHY_INTEGER;

33
src/scene/musicnode.cpp Normal file
View File

@ -0,0 +1,33 @@
#include "musicnode.h"
MusicNode::MusicNode(std::string musicFileName):
m_music_file(musicFileName)
{
}
void MusicNode::init(){
m_valid = m_music.openFromFile(m_music_file);
}
void MusicNode::play()
{
if (m_valid)
m_music.play();
}
void MusicNode::pause()
{
if(m_valid)
m_music.pause();
}
void MusicNode::stop()
{
if(m_valid)
m_music.stop();
}
void MusicNode::setPlayingOffset(int offset)
{
m_music.setPlayingOffset(sf::seconds(offset));
}

21
src/scene/musicnode.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef MUSICNODE_H
#define MUSICNODE_H
#include "scenenode.h"
#include "SFML/Audio.hpp"
class MusicNode : public SceneNode
{
sf::Music m_music;
std::string m_music_file;
bool m_valid;
public:
MusicNode(std::string musicFileName);
void init();
void play();
void pause();
void stop();
void setPlayingOffset(int offset);
};
#endif // MUSICNODE_H

View File

@ -2,6 +2,8 @@
#include "SparrowRenderer/mesh.h"
#include "SparrowRenderer/pbrmaterial.h"
#include "scene/scenetree.h"
PhysicsDebugNode::PhysicsDebugNode() :
MeshNode(new Mesh())
{
@ -37,6 +39,6 @@ void PhysicsDebugNode::flushLines()
void PhysicsDebugNode::clearBuffers()
{
m_geometry.mesh->positions3D.clear();
m_geometry.mesh->normals.clear();
m_geometry.mesh->m_positions3D.clear();
m_geometry.mesh->m_normals.clear();
}

View File

@ -11,6 +11,7 @@
#include "scenetree.h"
#include "lightnode.h"
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#define DEFAULT_ROTATION_SPEED 0.001f
#define TRIGGER_VALUE 15
@ -297,6 +298,10 @@ void PlayerCharacterNode::update()
m_rigidBody->setLinearVelocity(newVelocity);
}
m_playerLightNode->update();
glm::vec3 p = this->getEyePosition();
sf::Listener::setPosition(p.x,p.y,p.z);
glm::vec3 d = getDirection();
sf::Listener::setDirection(d.x,d.y,d.z);
}
void PlayerCharacterNode::toggleNoClip()

47
src/scene/soundnode.cpp Normal file
View File

@ -0,0 +1,47 @@
#include "soundnode.h"
#include "resourcemanager.h"
SoundNode::SoundNode(std::string soundFileName):
m_sound_file(soundFileName)
{
}
void SoundNode::init()
{
if ((m_valid = RESOURCE_CHECK(sf::SoundBuffer,m_sound_file)))
m_sound.setBuffer(*RESOURCE_GET(sf::SoundBuffer, m_sound_file));
else{
sf::SoundBuffer* buffer;
m_valid = buffer->loadFromFile(m_sound_file);
if(m_valid){
RESOURCE_ADD(buffer,sf::SoundBuffer,m_sound_file);
m_sound.setBuffer(*buffer);
}
}
}
void SoundNode::play()
{
if (m_valid)
m_sound.play();
}
void SoundNode::pause()
{
if(m_valid)
m_sound.pause();
}
void SoundNode::stop()
{
if(m_valid)
m_sound.stop();
}
void SoundNode::setPosition(glm::vec3 pos,bool relative)
{
m_sound.setPosition(pos.x,pos.y,pos.z);
m_sound.setRelativeToListener(relative);
}

22
src/scene/soundnode.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef SOUNDNODE_H
#define SOUNDNODE_H
#include "scene/scenenode.h"
#include "SFML/Audio.hpp"
#include "glm/vec3.hpp"
class SoundNode : public SceneNode
{
sf::Sound m_sound;
std::string m_sound_file;
bool m_valid;
public:
SoundNode(std::string soundFileName);
void init();
void play();
void pause();
void stop();
void setPosition(glm::vec3 pos, bool relative);
};
#endif // SOUNDNODE_H

View File

@ -85,6 +85,7 @@ public:
unsigned int getIndex(){return m_buffer->getIndex();}
ShellBuffer* getBuffer(){return m_buffer;}
ScriptNode* getScript(){return m_script;}
void setInputs(int cursor_left, int cursor_right, int history_up, int history_down);

View File

@ -99,7 +99,7 @@ void generateTerrain(SceneTree *scene, btDiscreteDynamicsWorld *world)
Chunk *chunk = new Chunk(&gen); // ! WARNING ! : chunk pointer is lost and never deleted
glm::vec3 pos(x, y, z);
chunk->generate(pos);
if(chunk->mesh->positions3D.empty())
if(chunk->mesh->m_positions3D.empty())
delete chunk;
else
{

View File

@ -68,7 +68,7 @@ Potator::Potator(PlayerCharacterNode * player,
m_cubeMesh->addTriangle(id+7, id+5, id+6);
}
PBRMaterial *mat = new PBRMaterial(); /*
PBRMaterial *mat = new PBRMaterial();
Image* img = Loader::loadImage("woodframe_albedo.png", 24);
mat->setTexture(PBRMaterial::ALBEDO_SLOT, new Texture(img));
img = Loader::loadImage("woodframe_metallic.png", 8);
@ -76,7 +76,7 @@ Potator::Potator(PlayerCharacterNode * player,
img = Loader::loadImage("woodframe_roughness.png", 8);
mat->setTexture(PBRMaterial::ROUGHNESS_SLOT, new Texture(img));
img = Loader::loadImage("woodframe_normal.png", 24);
mat->setTexture(PBRMaterial::NORMALS_SLOT, new Texture(img)); */
mat->setTexture(PBRMaterial::NORMALS_SLOT, new Texture(img));
m_cubeMesh->setMaterial(mat);
m_cubeMesh->computeTangents();
@ -183,7 +183,7 @@ void Potator::update()
throwSword();
}
}
/*
ImGui::Begin("Potator");
if(ImGui::Button("Load pack"))
LoadingThread::get()->loadResourcePack("woodbox");
@ -197,4 +197,5 @@ void Potator::update()
m_scene->registerMeshType(m_cubeMesh->getFlags());
}
ImGui::End();
*/
}

View File

@ -216,7 +216,7 @@ std::vector<Mesh*> Loader::loadMesh(const std::string &filename){
std::sscanf(line.c_str(),"f %d/%d/%d %d/%d/%d %d/%d/%d",tab,tab+1,tab+2,tab+3,tab+4,tab+5,tab+6,tab+7,tab+8);
//TODO: check sscanf success
int nb_vertices = currentMesh->positions3D.size();
int nb_vertices = currentMesh->m_positions3D.size();
currentMesh->addTriangle(nb_vertices, nb_vertices+1, nb_vertices+2);
for(int i=0; i<3; ++i)
@ -278,7 +278,7 @@ std::vector<Mesh*> Loader::loadMesh(const std::string &filename){
for(std::size_t i=0; i<meshes.size(); ++i)
{
if(meshes[i]->indices.size() == 0)
if(meshes[i]->m_indices.size() == 0)
{
meshes[i] = meshes.back();
meshes.pop_back();
@ -287,7 +287,7 @@ std::vector<Mesh*> Loader::loadMesh(const std::string &filename){
else
{
Mesh* m = meshes[i];
if(m->normals.empty())
if(m->m_normals.empty())
m->computeNormals();
if(m->getFlags() & (1 << Mesh::MATERIAL_PBR_NORMAL_MAP))
m->computeTangents();