Hi Guys

I惴 trying to convert the following routine to asm:


int mcount=0;
int mindex=0;

  for(int i=0;i<sizeof(face_indicies)/sizeof(face_indicies[0]);i++)
{
      if(!mcount)
      {
        SelectMaterial(material_ref[0]);
        mcount=material_ref[1];
        mindex++;
      }
      mcount--;
for(int j=0;j<3;j++)
{
int vi=face_indicies;
int ni=face_indicies;
int ti=face_indicies;
glNormal3f (normals[0],normals[1],normals[2]);
glTexCoord2f(textures[0],textures[1]);
glVertex3f (vertices[0],vertices[1],vertices[2]);
        }
      }

Ehere the variables are:
static short face_indicies[15680][9] = {
// H0_C_0
{2,1,0 ,0,1,2 ,0,1,2 }, {4,3,1 ,3,4,1 ,3,4,1 },
.....................

static int material_ref [1][2] = {
{0,15680}
};

.........
static GLfloat normals [744][3] = {
{0.353102f,0.924082f,0.14626f},{0.382195f,0.924082f,0.0f},
..........................
static GLfloat textures [185][2] = {
{0.0625f,0.875f},{0.0f,0.875f},{0.03125f,1.0f},
..................................

static GLfloat vertices [5165][3] = {
{-0.00680804f,0.00424107f,0.361161f},{0.0113438f,0.000630464f,0.361161f},

Note: I know that sizeof(face_indicies)/sizeof(face_indicies[0]) = 15680



My problem is with the array indexes...What a hell is:


int vi=face_indicies;
int ni=face_indicies;
int ti=face_indicies;


or

glNormal3f (normals[0],normals[1],normals[2]);


or

        SelectMaterial(material_ref[0]);
        mcount=material_ref[1];


??????????

I have no idea how those arrays can be translated to assembly, and used inside a while routine. (The "For' routine is, in fact a While in assembly....ok..but how translate the arrays ?)



Someone can help me translating this arrays ?


Best Regards,

Guga
Posted on 2006-05-10 22:27:09 by Beyond2000!
A quick glance reveals that the code determines the index count of the array, and proceeds to processes each array in a sequential manner, starting from "0" (but using i and j from the for loops as counters).

All-in-all, it is just looks more complex than it really is. It is a system of variables and arrays based on other variables and arrays. Considering the names of variables and arrays used *cough* gl *cough*, I would say that this has to do with game programming in some direct or indirect way, so it makes pretty good sense.

Considering that, I would say that the "j+3" type stuff is a point/vertex system (relative position in the array creates an absolute reference.)

That code is probably a little beyond my attention span or general understanding right now, but I bet Homer could help you more easily, correctly, and simply than I could hope to :)

He shows up often, so just some patience and your question should be answered to your satisfaction.
Posted on 2006-05-11 00:10:56 by SpooK
Hi Spook

tks...It is not exactly a game programming. It is a molecular model viewer i惴 making. I suceed to make the model show up. But this array stuff is really killing.

Best Regards,

Guga
Posted on 2006-05-11 00:22:14 by Beyond2000!
I see.

Right now, the array parser looks 2-fold. It is parsing all sub-arrays of each array (hence the j of i).

I said that this can be explained better, but I offer to explain it in a way that I "explain" things to myself when breaking stuff down to assembly language.

i starts off as zero. Then j is used to go through each set of points in the index. In short...


  • vi = the first point when j = 0, fourth point when j = 1, and seventh point when j = 2

  • ni = the second point when j = 0, fifth point when j = 1, and eighth point when j = 2

  • ti = the third point when j = 0, sixth point when j = 1, and ninth point when j = 2



So in a quick way, your assembly language equivalent (please note that I am a NASM buff) could look like so...

;Assmue sizeof was used from Windows API call and value is now stored in EAX, divide EAX by 9 (quick and dirty way of doing it)

;for i
parse_array:
mov ebx,eax
shl ebx,1                        ;Extrapolate array position
                                      ;Assume WORD (16-bit) sized array index
mov ecx,ebx                  ;ECX = EBX
add ecx,18                    ;Set ECX to the index "j" limit we wish to use ((3*3) * 2)
cmp BYTE,al              ;Compare AL to i
jl .parse_subarray        ;Process array if we are within the array size limit
jmp .end                      ;Otherwise, end processing

;for j
.parse_subarray:
add ebx,face_indicies    ;Add base address of the master array to EBX (array offset)
mov dx,WORD      ;Load first indexed point
mov WORD,dx          ;Store value of first indexed point into VI
mov dx,WORD  ;Load second indexed point (+3, but WORD size makes it +6)
mov WORD,dx          ;Store value of second indexed point into NI
mov dx,WORD ;Load third indexed point (+6, but WORD size makes it +12)
mov WORD,dx          ;Store value of third indexed point into TI

;blah blah blah... more stuff...

add ebx,2                      ;Increase array offset by one (but acknowledge WORD size)
cmp ebx,ecx                  ;Have we processed all sub_arrays???
jl .parse_subarray        ;If not, keep processing!!!

inc BYTE                    ;Increment i
jmp parse_array          ;Keep processing array...

.end:
;umm... are we finished???


I kind of slapped that together quick and dirty like, might be a few logic/grammatical errors as well... but you should get a general idea of how you can access the values of these arrays (other methods can be used as well).
Posted on 2006-05-11 01:30:10 by SpooK
It's using OpenGL (obviously), but it doesn't use vertex buffers, which is a *SERIOUS* preformance penalty.

好bsp; 好bsp; 好bsp; 好bsp;int vi=face_indicies;
好bsp; 好bsp; 好bsp; 好bsp;int ni=face_indicies;
好bsp; 好bsp; 好bsp; 好bsp;int ti=face_indicies;

vi = vertex index
ni - normal index ( normals follow vertices)
ti - texture index ( texture coordinates follow normals)

1 vertex here is X;Y;Z;Xn;Yn;Zn;Tu;Tv; , so it takes 8 elements (usually 32-bit floating pointvalues) to describe a vertex. 3 vertices are requiredd to form a 'face' (a triangle in such case).

glNormal ('3f' in this case) sets current normal vecotr. OpengGL is a state machine - it works according to many 'states'. glNormal3f sets the 'actual normal' state. Vertex/Index buffers are used to drastically speed up the rendering process (which is not being done here). glMaterial is used to set 'actual material' state.
Posted on 2006-05-11 03:23:12 by ti_mo_n
Hi ti_mo_n

Tks

So i need here 8 Buffers, right  ?

Ok..but concernign the arrat..i惴 still not following the translation to asm of it.


Do you need me to post teh entire C function to you take a look ?


Best REgards

Guga
Posted on 2006-05-11 04:03:15 by Beyond2000!