bloboland

changeset 5:2f4406cc341e tip

meh
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 19 Dec 2012 02:37:20 +0200
parents 9021a906c5d3
children
files sdr/bloboray.p.glsl src/game.cc src/level.cc src/renderer.cc src/renderer.h src/texture.cc src/texture.h
diffstat 7 files changed, 36 insertions(+), 12 deletions(-) [+]
line diff
     1.1 --- a/sdr/bloboray.p.glsl	Tue Dec 18 06:13:09 2012 +0200
     1.2 +++ b/sdr/bloboray.p.glsl	Wed Dec 19 02:37:20 2012 +0200
     1.3 @@ -27,7 +27,7 @@
     1.4  vec3 get_blob(int i);
     1.5  
     1.6  #define BLOB_THRESHOLD	0.5
     1.7 -#define BLOB_SCALE		(1.0 / 4.0)
     1.8 +#define BLOB_SCALE		0.1
     1.9  #define MAX_ITER		1
    1.10  
    1.11  #define RAY_STEP	(0.75 / volsize.z)
    1.12 @@ -184,8 +184,11 @@
    1.13  	float val = 0.0;
    1.14  
    1.15  	for(int i=0; i<num_blobs; i++) {
    1.16 -		float dist = length(pt - get_blob(i));
    1.17 -		val += (dist * dist * (3.0 - 2.0 * dist));
    1.18 +		/*float dist = length(pt - get_blob(i));
    1.19 +		val += (dist * dist * (3.0 - 2.0 * dist));*/
    1.20 +		vec3 blobvec = pt - get_blob(i);
    1.21 +		float dist_sq = dot(blobvec, blobvec);
    1.22 +		val += BLOB_SCALE / dist_sq;
    1.23  	}
    1.24  	return val;
    1.25  }
     2.1 --- a/src/game.cc	Tue Dec 18 06:13:09 2012 +0200
     2.2 +++ b/src/game.cc	Wed Dec 19 02:37:20 2012 +0200
     2.3 @@ -22,6 +22,7 @@
     2.4  
     2.5  static const float fog_color[] = {0.76, 0.64, 0.91, 1.0};
     2.6  static Vector3 gravity;
     2.7 +#define DAMPING	0.95
     2.8  
     2.9  bool game_init()
    2.10  {
    2.11 @@ -51,7 +52,7 @@
    2.12  	glClearColor(fog_color[0], fog_color[1], fog_color[2], 1.0);
    2.13  	glFogfv(GL_FOG_COLOR, fog_color);
    2.14  
    2.15 -	gravity = Vector3(0, -0.01, 0);
    2.16 +	gravity = Vector3(0, -0.5, 0);
    2.17  
    2.18  	return true;
    2.19  }
    2.20 @@ -91,9 +92,12 @@
    2.21  
    2.22  		Vector3 normal;
    2.23  		if(level->collision(b->pos, npos, &npos, &normal)) {
    2.24 -			b->velocity = b->velocity.reflection(normal);
    2.25 +			printf("%d: COLLISION (%.2f %.2f %.2f)\n", (int)i, npos.x, npos.y, npos.z);
    2.26 +			b->velocity = b->velocity.reflection(normal) * DAMPING;
    2.27  		}
    2.28 +		b->pos = npos;
    2.29  	}
    2.30 +	rend->prepare();
    2.31  }
    2.32  
    2.33  void game_render()
     3.1 --- a/src/level.cc	Tue Dec 18 06:13:09 2012 +0200
     3.2 +++ b/src/level.cc	Wed Dec 19 02:37:20 2012 +0200
     3.3 @@ -73,7 +73,8 @@
     3.4  	// generate some blobs
     3.5  	for(int i=0; i<opt.gen_num_blobs; i++) {
     3.6  		Blob b;
     3.7 -		b.pos = Vector3(frand(1.0) - 0.5, 10.0, frand(1.0) - 0.5);
     3.8 +		b.pos = Vector3(frand(1.0) - 0.5, 2.0, frand(1.0) - 0.5) * 2.0;
     3.9 +		printf("blob[%d]: %f %f %f\n", i, b.pos.x, b.pos.y, b.pos.z);
    3.10  		b.velocity = Vector3(0, 0, 0);
    3.11  		blobs.push_back(b);
    3.12  	}
     4.1 --- a/src/renderer.cc	Tue Dec 18 06:13:09 2012 +0200
     4.2 +++ b/src/renderer.cc	Wed Dec 19 02:37:20 2012 +0200
     4.3 @@ -31,6 +31,7 @@
     4.4  	leveltex->create(vol->get_size(0), vol->get_size(1), vol->get_size(2));
     4.5  
     4.6  	blobtex = new Texture1D;
     4.7 +	blobtex->set_pixel_format(GL_RGBA16F);	// floating point textures
     4.8  	blobtex->create(level->blobs.size());
     4.9  	blobtex->set_filtering(GL_NEAREST);
    4.10  
    4.11 @@ -59,11 +60,14 @@
    4.12  
    4.13  static void draw_cube(const Vector3 &pos, float sz);
    4.14  
    4.15 +void Renderer::prepare()
    4.16 +{
    4.17 +	leveltex->update((float*)level->terrain->get_data_ptr());
    4.18 +	update_blobtex();
    4.19 +}
    4.20 +
    4.21  void Renderer::render() const
    4.22  {
    4.23 -	leveltex->update((float*)level->terrain->get_data_ptr());
    4.24 -	((Renderer*)this)->update_blobtex();
    4.25 -
    4.26  	bind_texture(leveltex, 0);
    4.27  	bind_texture(blobtex, 1);
    4.28  
    4.29 @@ -73,6 +77,8 @@
    4.30  			level->terrain->get_size(1), level->terrain->get_size(2));
    4.31  	set_uniform_float4(sdrprog, "camprop", fov, aspect, 0, 0);
    4.32  
    4.33 +	set_uniform_int(sdrprog, "num_blobs", (int)level->blobs.size());
    4.34 +
    4.35  	set_uniform_int(sdrprog, "voltex", 0);
    4.36  	set_uniform_int(sdrprog, "blobtex", 1);
    4.37  	bind_program(sdrprog);
     5.1 --- a/src/renderer.h	Tue Dec 18 06:13:09 2012 +0200
     5.2 +++ b/src/renderer.h	Wed Dec 19 02:37:20 2012 +0200
     5.3 @@ -25,6 +25,7 @@
     5.4  	void set_fov(float fov);
     5.5  	void set_aspect(float aspect);
     5.6  
     5.7 +	void prepare();
     5.8  	void render() const;
     5.9  };
    5.10  
     6.1 --- a/src/texture.cc	Tue Dec 18 06:13:09 2012 +0200
     6.2 +++ b/src/texture.cc	Wed Dec 19 02:37:20 2012 +0200
     6.3 @@ -25,6 +25,7 @@
     6.4  Texture::Texture()
     6.5  {
     6.6  	type = 0;
     6.7 +	intfmt = GL_RGBA;
     6.8  
     6.9  	size[0] = size[1] = size[2] = 0;
    6.10  
    6.11 @@ -38,6 +39,11 @@
    6.12  	}
    6.13  }
    6.14  
    6.15 +void Texture::set_pixel_format(unsigned int fmt)
    6.16 +{
    6.17 +	intfmt = fmt;
    6.18 +}
    6.19 +
    6.20  void Texture::set_filtering(unsigned int min_filter, unsigned int mag_filter)
    6.21  {
    6.22  	if(mag_filter == 0) {
    6.23 @@ -74,7 +80,7 @@
    6.24  void Texture1D::create(int sz, float *data)
    6.25  {
    6.26  	glBindTexture(type, tex);
    6.27 -	glTexImage1D(type, 0, GL_RGBA, sz, 0, GL_RGBA, GL_FLOAT, data);
    6.28 +	glTexImage1D(type, 0, intfmt, sz, 0, GL_RGBA, GL_FLOAT, data);
    6.29  
    6.30  	size[0] = sz;
    6.31  }
    6.32 @@ -97,7 +103,7 @@
    6.33  void Texture2D::create(int xsz, int ysz, float *data)
    6.34  {
    6.35  	glBindTexture(type, tex);
    6.36 -	glTexImage2D(type, 0, GL_RGBA, xsz, ysz, 0, GL_RGBA, GL_FLOAT, data);
    6.37 +	glTexImage2D(type, 0, intfmt, xsz, ysz, 0, GL_RGBA, GL_FLOAT, data);
    6.38  
    6.39  	size[0] = xsz;
    6.40  	size[1] = ysz;
    6.41 @@ -124,7 +130,7 @@
    6.42  void Texture3D::create(int xsz, int ysz, int zsz, float *data)
    6.43  {
    6.44  	glBindTexture(type, tex);
    6.45 -	glTexImage3D(type, 0, GL_RGBA, xsz, ysz, zsz, 0, GL_RGBA, GL_FLOAT, data);
    6.46 +	glTexImage3D(type, 0, intfmt, xsz, ysz, zsz, 0, GL_RGBA, GL_FLOAT, data);
    6.47  
    6.48  	size[0] = xsz;
    6.49  	size[1] = ysz;
     7.1 --- a/src/texture.h	Tue Dec 18 06:13:09 2012 +0200
     7.2 +++ b/src/texture.h	Wed Dec 19 02:37:20 2012 +0200
     7.3 @@ -5,6 +5,7 @@
     7.4  protected:
     7.5  	unsigned int type;
     7.6  	unsigned int tex;
     7.7 +	unsigned int intfmt;
     7.8  
     7.9  	int size[3];
    7.10  
    7.11 @@ -12,6 +13,8 @@
    7.12  	Texture();
    7.13  	virtual ~Texture();
    7.14  
    7.15 +	virtual void set_pixel_format(unsigned int fmt);
    7.16 +
    7.17  	virtual void set_filtering(unsigned int min_filter, unsigned int mag_filter = 0);
    7.18  	virtual void set_wrapping(unsigned int wrap);
    7.19