Converting 3D position to 2d screen position [r69!]

I’ve written for my project the following function; it receives an THREE.Object3D instance and a camera as a parameters and returns the position on the screen. function toScreenPosition(obj, camera) { var vector = new THREE.Vector3(); var widthHalf = 0.5*renderer.context.canvas.width; var heightHalf = 0.5*renderer.context.canvas.height; obj.updateMatrixWorld(); vector.setFromMatrixPosition(obj.matrixWorld); vector.project(camera); vector.x = ( vector.x * widthHalf ) + widthHalf; … Read more

Sending and receiving 2D array over MPI

Just to amplify Joel’s points a bit: This goes much easier if you allocate your arrays so that they’re contiguous (something C’s “multidimensional arrays” don’t give you automatically:) int **alloc_2d_int(int rows, int cols) { int *data = (int *)malloc(rows*cols*sizeof(int)); int **array= (int **)malloc(rows*sizeof(int*)); for (int i=0; i<rows; i++) array[i] = &(data[cols*i]); return array; } /*…*/ … Read more

Allocate memory 2d array in function C

Your code is wrong at *arr[i]=(int*)malloc(m*sizeof(int)); because the precedence of the [] operator is higher than the * deference operator: In the expression *arr[i], first arr[i] is evaluated then * is applied. What you need is the reverse (dereference arr, then apply []). Use parentheses like this: (*arr)[i] to override operator precedence. Now, your code … Read more