Jump to content

  • Log In with Google      Sign In   
  • Create Account


usbman3

Member Since 19 Sep 2010
Offline Last Active Dec 05 2011 04:03 PM
-----

Posts I've Made

In Topic: Any fast voxel rendering algorithms?

21 March 2011 - 07:51 AM

Voxels are simple, so I though rendering them would be simple as well. Apparently not.

I don't want to spend my life on this, so I forget voxels and start doing something else instead.

Thanks for your replies, though. :)

In Topic: Quaternions

15 January 2011 - 07:37 AM

I randomly messed with it and finally got it working as it should:
static void rotate_bone_2( Bone *bone, float angle )
{
	float axis[3] = {0.0f};
	float rotation[4];
	float inverse[4];
	float boneRot[4];
	
	// get rotation quaternion
	axis[the_axis] = 1.0f;
	axis_to_quat( axis, angle, rotation );
	
	// get original bone rotation
	memcpy( boneRot, bone->quat, sizeof(float)*4 );
	
	Bone *temp;
	Bone *bones[80] = {NULL};
	int num_bones = 0;
	int n;
	
	// collect the bones in order
	for( temp=bone; temp; temp=temp->parent )
		bones[num_bones++] = temp;
	
	// convert from bone space to world space
	for( n=1; n<num_bones; n++ )
	{
		get_inverse_quat( bones[n]->quat, inverse );
		memcpy( inverse, bones[n]->quat, sizeof(float)*4 );
		multiply_quat( boneRot, bones[n]->quat );
	}
	
	// apply rotation
	multiply_quat( boneRot, rotation );
	
	// convert from world space to bone space
	for( n=num_bones-1; n>0; n-- )
	{
		get_inverse_quat( bones[n]->quat, inverse );
		multiply_quat( boneRot, inverse );
	}
	
	// normalize
	normalize_quat( boneRot );
	memcpy( bone->quat, boneRot, sizeof(float)*4 );
}

rotate_bone() converts the rotation quaternion to bone space and then multiplies the original rotation with it.
rotate_bone_2() converts the original rotation to world space, multiplies by rotation quaternion, and converts back to bone space.

But why only rotate_bone_2() works? Aren't they doing the same thing?

In Topic: 3D texture coordinate generation doesn't work as expected, need some help

30 December 2010 - 03:23 AM

Quote:
Original post by Erik Rufelt
Try setting the GL_OBJECT_PLANE for GL_R manually, as I believe the defaults are {0, 0, 0, 0} for GL_R.

GLfloat plane[4] = {0.0f, 0.0f, 1.0f, 0.0f};
glTexGenfv(GL_R, GL_OBJECT_PLANE, plane);


Now texture coordinate generation and glutSolidCube work properly. Thanks.

But lighting doesn't work with either methods. Just with the 2D texture. (I have added a normal array to draw_cube()).

What might be the problem with lighting?
EDIT: Lighting didn't work because I didn't have the glMaterial(...) calls in the new functions which use 3D textures.

Just to make it clear, there are no problems anymore (so don't try to help). Thanks for your replies.


[Edited by - usbman3 on December 30, 2010 10:23:23 AM]

In Topic: 3D texture coordinate generation doesn't work as expected, need some help

30 December 2010 - 02:53 AM

I wrote my own functions for rendering cubes:

#include <GL/gl.h>
#include "cube.h"

static const GLshort the_coords[] = {
-1,-1,-1, // 0
-1,-1,1, // 1
-1,1,-1, // 2
-1,1,1, // 3
1,-1,-1, // 4
1,-1,1, // 5
1,1,-1, // 6
1,1,1, // 7
};

static const GLubyte indexes[] = {
// x/y top
1,5,7,3,
// x/y bottom
0,2,6,4,
// z/x
3,7,6,2,
// -------
1,0,4,5,
// z/y
4,6,7,5,
// -------
0,1,3,2
};

void begin_cubes( void )
{
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );

glVertexPointer( 3, GL_SHORT, 0, the_coords );
glTexCoordPointer( 3, GL_SHORT, 0, the_coords );
}

void draw_cube( void )
{
glDrawElements( GL_QUADS, 24, GL_UNSIGNED_BYTE, indexes );
}

void end_cubes( void )
{
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glDisableClientState( GL_NORMAL_ARRAY );
}




It worked just like glutSolidCube.

Then I removed OpenGL texture coordinate generation stuff.

Now it works as it should:


But I still don't know what was wrong with GL_TEXTURE_GEN_R. I guess it's just the broken ATI drivers, whatever...

In Topic: 3D texture coordinate generation doesn't work as expected, need some help

29 December 2010 - 11:53 AM

Unfortunately none of those debugging tools are available in kubuntu repos (I could install them manually but I'm lazy and I do that only if I can't solve this without them).

If I don't initialize the texture pixels at all (they're random!), I still get incorrect texture coordinates, so the problem can not be in the texture generating function.

PARTNERS