Tuesday 15 September 2015

objective c - Passing array of float pointers into VBO -


I am creating a particle system renderer, the problem is that all particle positions are explained in those sections which Integrate with and do some other stuff, instead of copying values ​​into a different array to represent each frame, I have created a point structure like this that I can once use to indicate all the values :

  typedef str Uct {float * x, * y, * z; } Point;   

Then I malloc an array of these as the size of the particles of their size.

Announcement at the top:

  point * digits;   

Molok:

  point = maulok (size) * [particle count]);   

I copy the loop through all the particles and the position of each position in the same position:

 for  (int i = 0; I & lt; [Particle count]; ++ i) {number [i] .x = & amp; [[Particle ObjectTitx: I] Getposition]. X; Number [i] .y = & amp; [[PARTICLE ObjectOutIndexX: I] GETPASION] .y; Number [i] .z = & amp; [[The particle object atx: i] getposition] .z; }   

My position function returns only one vector strat (float x, y, z).

My first problem is that when I value like:

  NSLog (@ "% f", * digit [0]. X);   

Instead of reading the value (say: 0.5), it is round and denial (this shows: -1.0).

Then I get the data VBO in such a way:

  glBufferData (GL_ARRAY_BUFFER, size) * [particle count], and number [0], GLDVNAMCRADW);   

I think this is also wrong, but there is no information about how to pass the Points in VBO.

What you are doing is wrong because everything in C is passed by value, so when you return This is doing a copy of the structure of the .x structure, which will be popped from the stack if not assigned to any value.

You are wrong in design, There is no need to be a strict like:

  typedef struct {float * x, * y, * z;} point;   

:

  typedef struct {float x, y, z;}   

if you Even if they want to assign it to the original value, then the value of the original form changes, then this structure also changes, then you will need a heater which is an indicator for a structure, and keep an indicator with it: / P>

  numeral [i] = [[particle object atinaxx: i] getPositionPointer];   

In this way you are certain that your strat has the same value as the original structure , But you're violating the encapsulation that I think might be Ul structure does not need to hold a pointer, but that is no reason to do so, I showed you the way.

No comments:

Post a Comment