Skip to content

Instantly share code, notes, and snippets.

const std::string SimpleParticleShader::VS = "#version 330 core\n"
"layout ( location = 0 ) in vec3 vertex_position;"
"layout ( location = 4 ) in vec4 position;"
"uniform mat4 M_v;"
"uniform mat4 M_p;"
"uniform float particleSize;"
"out float lifetime;"
"void main()"
"{"
" vec4 position_viewspace = M_v * vec4( position.xyz , 1 );"
SimpleEmitter::SimpleEmitter()
{
// create 100 particles
this->particles.resize( 100 );
for ( uint i = 0 ; i < this->particles.size() ; ++i )
{
// give every particle a random position
this->particles[i].position = lstd_random_between( vec3( -1.0f ) , vec3( 1.0f ) );
this->particles[i].lifetime = lstd_random_between( 1.0f , 2.0f );
}
void SimpleEmitter::update( const float dt )
{
for ( uint i = 0 ; i < this->particles.size() ; ++i )
{
// subtract from the particles lifetime
this->particles[i].lifetime -= dt;
// if the lifetime is below 0 respawn the particle
if ( this->particles[i].lifetime <= 0.0f )
{
void SimpleEmitter::draw()
{
glEnableVertexAttribArray( 0 );
glEnableVertexAttribArray( 4 );
// update the position buffer
glBindBuffer( GL_ARRAY_BUFFER , this->positionBuffer );
glBufferSubData( GL_ARRAY_BUFFER , 0 , this->particles.size()*4*sizeof(float) , this->positions );
// vertex buffer
#pragma once
#include "Z:/cpp/SRC/lgl3/include/lgl3_includes.hpp"
#include "Z:/cpp/SRC/lgl3/include/lglShader.hpp"
/*
emitter
*/
#include "SimpleParticles.hpp"
/*
emitter
*/
@pingpoli
pingpoli / Owl.hpp
Last active September 5, 2020 10:32
#pragma once
#include <fstream>
#include <iostream>
#include <string>
#include "timeutil.hpp"
#include "util.hpp"
class Owl;
extern Owl owlInstance;
#include "Owl.hpp"
Owl owlInstance;
Owl::Owl()
{
this->b_init = false;
}
Owl::~Owl()
@pingpoli
pingpoli / vec3.hpp
Last active September 9, 2020 20:21
class vec3
{
public:
float x;
float y;
float z;
vec3( const float x = 0 , const float y = 0 , const float z = 0 ) : x(x) , y(y) , z(z) {}
// add another vector to a vector like a += v;
<script src="js/CookieConsentManager.js"></script>
<script>CCM_getCookieConsent();</script>