I'm a newb, need help with vertices

While I’m attempting to port my existing angle math (because of structs, enums, etc) into this new project of mine and try to rotate my triangle, mind taking a look at this extract and telling me if you see any potential issues, particularly with the comments

/* p = positive, n = negative */
typedef enum _angle_corner
{
	angle_corner_pp = 0
	angle_corner_np,
	angle_corner_nn,
	angle_corner_pn,
	angle_corner_count
} angle_corner;

/*
 * p = positive,
 * n = negative,
 * r = real number,
 * i = "imaginary" number - I think of it as paired numbers
 * For example the square root of 25 is 5 right? But what about the square
 * root of -25? That needs 5 * -5, that pair is referred to as i5, or in other
 * words an "imaginary" 5
*/
typedef enum _angle_side
{
	angle_corner_pr = 0
	angle_corner_pi,
	angle_corner_nr,
	angle_corner_ni,
	angle_corner_count
} angle_side;

I have a means of calculating the offsets of existing points but I don’t yet have any ideas on how to calculate which angle to apply in the 1st place, do I just multiply them against the normalised offsets produced by the angle math? How would peops here apply the normalised locations provide by angle math?

Edit: Had an idea of how to apply it now, I just need to figure out how I reversed the normalised points then I can see if it works correctly, roughly speaking it is along the lines of (pos * mul) + char_pos GPU side and CPU side it is roughly:

face_spots( a, max, xy )
face_spots( a, max, zy )

mul.x = xy.r;
mul.y = -1.0 + xy.i + zy.i;
mul.z = zy.r;

I’m probably just calling the wrong function, I’ll come back to it later when I have time

Btw I made some changes to my uniforms to use ivec2/ivec3/vec3, just want to check I’m filling the values correctly as that would interfere with my analysis of what’s going wrong with my code

CPU side:

void update_object( uint loc, object *obj )
{
	glUniform2iv( loc + 1, 2, obj->rot );
	glUniform3iv( loc + 3, 3, obj->cell );
	glUniform3fv( loc + 6, 3, obj->pos );
	glUniform3fv( loc + 10, 3, obj->mul );
}

GPU side:

struct object
{
	ivec2 rot;
	ivec3 cell;
	vec3 pos;
	vec3 mul;
};

uniform object uChar0;
uniform object uView0;

Managed to fix the x axis, z axis is to be confirmed but for now it appears fine, the y axis however is not managing to enter negative space despite using the exact same function for rotating it’s points as the x axis:

void rot_pos3fv( DVEC2 rot, int max, FVEC3 pos )
{
	FVEC2 xz = {0}, yz = {0};
	rot_pos2fv( rot[VEC_X], max, xz );
	rot_pos2fv( rot[VEC_Y], max, yz );
	pos[VEC_X] = xz[VEC_R];
	pos[VEC_Y] = yz[VEC_R];
	pos[VEC_Z] = xz[VEC_I] * yz[VEC_I];
}

Not looking for help on that since that’s using code I plan to patent - assuming it IS faster than using sin/cos/tan (which if I remember rightly use sqrt which I expect is slower on average than a fixed number of operations). Anyways since this is the key function to test against when it comes to a speed test I thought I’d leave sin/cos/tan based one to whoever is interested enough to do it while I try to figure out why my y axis is off kilter. DVEC2 is is the array equivalent of ivec2 in glsl, likewise FVEC3 is the array equivalent of vec3 in glsl, max is just the max angle, think of it as you would 360, the angles in rot can be positive or negative, I use the below functions to clamp the angle and retrieve a relative position for the VEC_R axis (real number, max - the position should be for the imaginary axis)

uint fix_rot( int rot, int max )
{
	uint pos = (uint)max + (rot % max);
	return (pos == ((uint)max * 2)) ? max : pos % max;
}

uint rot_pos( int rot, int max )
{
	uint dbl = (uint)max * 2;
	uint qtr = max / 4;
	uint pos = fix_rot( rot, max );
	return (pos % qtr) * 4;
}

Edit: After commenting out the z axis line I found it wasn’t the y axis that was the problem, it’s the z axis, will need to think and experiment a bit.

Edit: Took a break and when I came back and tried again the problem had mysteriously vanished, will put that issue to one side for now and will instead work on adding another object to move, after that I will then try to load in a freely available model, then I will try to load a scene, when I can do all that I will move onto the next experimental code I want to develop that takes care of the infinity issue by splitting a scene into cells and normalising the model position to the cell, not the scene

Started thinking about how I would add another triangle to move independently of the first today and thought I should save myself some time by asking if this is roughly the right way to go about it:

typedef struct _LIST
{
	BYTES const perN;
	uint id;
	BYTES size;
	INDEX have;
	INDEX used;
	void *addr;
} LIST, BUFF, STR, WCS, TCS;
...
typedef struct _object
{
	uint vao;
	FVEC3 see;
	FVEC3 pos;
	IVEC3 eye;
	IVEC2 rot;
	BUFF buffers;
} object;

I’m planning to use the id member for the result of glGenBuffers and the vao for the result of glGenVertexArrays, unless I’ve misunderstood something or someone here has a better way to do it

Edit: Thought about it some more and decided this would be better than my previous thought:

typedef struct _object_part
{
	uint vao;
	FVEC3 see;
	FVEC3 pos;
	IVEC3 eye;
	IVEC2 rot;
	BUFF points;
} object_part;

typedef struct _object
{
	uint vao;
	object_part main;
	BUFF parts;
} object;

Vertex crafter:

#version 330

varying vec4 dye;

in vec3 vPos;
in vec3 vDye;

struct _object_part
{
	vec3 see;
	vec3 pos;
	ivec3 eye;
	ivec2 rot;
};

uniform _object_part main;
uniform _object_part part;

void main()
{
#if 1
	vec3 pxyz = (((vPos * part.see) + part.pos) * main.see) + main.pos;
	gl_Position = vec4(xyz, 1.0);
#else
	float x = (((vPos.x * part.see.x) + part.pos.x) * main.see.x) + main.pos.x;
	float y = (((vPos.y * part.see.y) + part.pos.y) * main.see.y) + main.pos.y;
	float z = (((vPos.z * part.see.z) + part.pos.z) * main.see.z) + main.pos.z;
    gl_Position = vec4(x, y, z, 1.0);
#endif
    dye = vec4(vDye,1.0);
}

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.