C gl-matrix, how to create vectors and matrices? -


it's code vec3.c in gl-matrix.

vec3_t vec3_create(vec3_t vec) { vec3_t dest = calloc(sizeof(double_t), 3);  if (vec) {     dest[0] = vec[0];     dest[1] = vec[1];     dest[2] = vec[2]; } else {     dest[0] = dest[1] = dest[2] = 0; }  return dest; } 

how can crate new vector using function? how create vector different values? trying set double values array this:

vec3_t vec; vec3_t vec3_create(vec); vec[0] = 1.0; vec[1] = 0.0; vec[2] = 0.0; 

but exc_bad_access. have same problem matrices.

code in mat4.c in gl-matrix.

mat4_t mat4_create(mat4_t mat) { mat4_t dest = calloc(sizeof(double), 16);  if (mat) {     dest[0] = mat[0];     dest[1] = mat[1];     dest[2] = mat[2];     dest[3] = mat[3];     dest[4] = mat[4];     dest[5] = mat[5];     dest[6] = mat[6];     dest[7] = mat[7];     dest[8] = mat[8];     dest[9] = mat[9];     dest[10] = mat[10];     dest[11] = mat[11];     dest[12] = mat[12];     dest[13] = mat[13];     dest[14] = mat[14];     dest[15] = mat[15]; }  return dest; } 

exc_bad_access.

mat4_t transform_mat; mat4_create(transform_mat); 

vec3_t pointer double defined in header

typedef double *vec3_t; 

from header find documentation, tell how use it:

/*  * vec3_t - 3 dimensional vector  */  /*  * vec3_create  * creates new instance of vec3_t  *  * params:  * vec - optional, vec3_t containing values initialize with. if null,   * vector initialized zeroes.  *  * returns:  * new vec3  */ vec3_t vec3_create(vec3_t vec); 

so might want this:

vec3_t vec = vec3_create(null); // vector 0s vec[0] = 1.0;                   // set first element 1.0 

in regard matrix:

mat4_t transform_mat = mat4_create(null); 

this allocate memory , transform_mat point address. need initialize values yourself, not initialized 0s default (as done vec3_t).


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -