gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Multiple MD2

#130338 - iainprice - Sat Jun 02, 2007 10:28 am

I loved Touch the Dead and wanted to have a play. So far I have this:

http://www.youtube.com/watch?v=AcnzP4Lhlhg

I have 2 MD2 files and picking working for finding them but they both use the same transfer matrix so they are on top of eachother, you click once and it kills one, then click again and it kills the other.

My HDD is playing up but I'll post some code later today.....

#130339 - iainprice - Sat Jun 02, 2007 10:37 am

OK, so that video was a biut naff ... here is a better one....

http://www.youtube.com/watch?v=rDrW0KkUYOs

Also I am after someone who can make me a nice alien MD2.......

#130350 - iainprice - Sat Jun 02, 2007 2:04 pm

[code]
if ((monsters[ii].health))
{
glPushMatrix();
glScalef32(scale);
glBindTexture (GL_TEXTURE_2D, Texture[0]);
glColorTable(GL_RGB256, TexturePal[0]);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(35, 256.0 / 192.0, 0.1, 40);
glMatrixMode(GL_MODELVIEW);
glTranslate3f32(monsters[ii].x, monsters[ii].y, monsters[ii].z+floattof32(-zoom));
glRotateX(rotateX-90);
glRotateZ(rotateY);
RenderMD2Model(monsters[ii].frame,monsters[ii].action);
glViewPort(0,192,0,192);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPickMatrix((touchXY.px),(191-touchXY.py),4,4,viewport); // render only below cursor
gluPerspective(35, 256.0 / 192.0, 0.1, 40);
glMatrixMode(GL_MODELVIEW);
startCheck();
QuickRenderMD2Model(monsters[ii].frame,monsters[ii].action);
endCheck(ii+1);
glPopMatrix(1);
}

[/code]

with different x y z values, they all seem to take the same position.. where am i going wrong?

Thanks.

#130356 - FireSlash - Sat Jun 02, 2007 3:40 pm

You're doing far too much there. The following lines should only be called once per render cycle

glPushMatrix();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glPopMatrix(1);

and these lines only need called once, before your render loop

glViewPort(0,192,0,192);
gluPerspective(35, 256.0 / 192.0, 0.1, 40);
_________________
FireSlash.net

#130370 - gabebear - Sat Jun 02, 2007 5:02 pm

Generally FireSlash would be almost correct, but when picking you need to constantly switch between rendering contexts. The posted code snippet looks correct.

Let me restate your problem so that I'm certain I have it right: you are rendering two models and they are being displayed in the exact same spot even through you translated differently before drawing.

I'm not sure what RenderMD2Model() does, but could it be loading identity on either GL_MODELVIEW or GL_POSITION? That seems like it is the most likely problem. That, or your moster x,y,z variables actually are the same for each monster.

With the endCheck()/startCheck() in the libnds example you can only select one item per frame, even if they are in the exact same spot, whatever was drawn last would be picked. The picking part seems to be working as expected.

#130393 - iainprice - Sat Jun 02, 2007 11:30 pm

[code]
void RenderMD2Model(int n,int num)
{
extern v16 anormtable16[162][3];

int i, j,stnum,vertnum;
if ( (n < 0) || (n > Models[num].header.num_frames - 1))
n=Models[num].header.num_frames - 1;
if(ModelEnable[num]==false)
return;

nds_vertex_t* vert=Models[num].frms[n].verts;
glBegin (GL_TRIANGLES);
for (i = 0; i < Models[num].header.num_tris; ++i){
for (j = 0; j < 3; ++j){
stnum=Models[num].tris[i].st[j];
vertnum=Models[num].tris[i].vertex[j];
glNormal(NORMAL_PACK(anormtable16[vert[vertnum].normalindex][0], anormtable16[vert[vertnum].normalindex][1], anormtable16[vert[vertnum].normalindex][2]));
glTexCoord2t16 (Models[num].uvs[stnum].s, Models[num].uvs[stnum].t);
glVertex3v16 (vert[vertnum].v[0],vert[vertnum].v[1], vert[vertnum].v[2]);
}
}
glEnd ();
}
[/code]

The Quick render doesn't bother with textures......

Any ideas....

#130405 - gabebear - Sun Jun 03, 2007 1:54 am

RenderMD2Model() looks fine as well... sorry

I guess I'd need to see the whole thing. You might want to try the #dsdev IRC channel. I sporadically hang out there.

On a side note, do you know how to get the MD2 anorms table under a non-GPL license? I've seen people redistributions anorms.h with the copyright information stripped off, but never with a license other than the GPL. I doubt Carmack would ever sue over it, but I'd love to know a legal place to get that table. I spent a little while trying to figure out how to generate the anorms table programmatically, but finally gave up.

#130438 - iainprice - Sun Jun 03, 2007 12:25 pm

I found it on the internet and it didn't say where it had come from so I presume it was stripped of copyright.... I'll try to find the source again and pm it to you for you to have a look at.

#130506 - a128 - Mon Jun 04, 2007 8:45 am

gabebear wrote:
I spent a little while trying to figure out how to generate the anorms table programmatically, but finally gave up.


Just calc your own normals from the verticies position


Code:

  // calculate polygon normals

  for (i = 0; i < m->numfaces; i++) {

   A = vertex1 - vertex3;

i.e. Ax=vertex1.x - vertex3.x
    ......
  Az=vertex1.z - vertex3.z

   B = vertex3-vertex2;

   C= A x B (crossproduct)
i.e.
    cx = ay * bz - by * az;
    cy = az * bx - bz * ax;
    cz = ax * by - bx * ay;

    len = 1.0f / sqrt(cx * cx + cy * cy + cz * cz);

    face normal[i]= C *len;

  }

  // calculate vertex normals by averaging the normals of all the polygons
  // which use the vertex.
  FLOAT count;

  for (i = 0; i < m->numverts; i++) {
    ax = ay = az = 0.0f;
    count = 0.0f;

    for (j = 0; j < m->numfaces; j++) {
      if (m->flist[j].v1 == i ||
          m->flist[j].v2 == i ||
          m->flist[j].v3 == i) {
        ax = ax + m->face normal [j]
        ay = ay + m->face normal[j]
        az = az + m->face normal[j]
        count++;
      }
    }
    m->vlist[i].nx = ax / count;
    m->vlist[i].ny = ay / count;
    m->vlist[i].nz = az / count;
  }

#132083 - tepples - Sat Jun 23, 2007 5:37 am

gabebear wrote:
On a side note, do you know how to get the MD2 anorms table under a non-GPL license?

Today I investigated anorms, and the set of 162 normal vectors it contains turn out to be an icosahedron, subdivided by a factor of 4, projected onto a unit sphere.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.