Ejemplo n.º 1
0
void
matrixutil_swap_yz (Mtx src, Mtx dst)
{
  float tx, ty, tz;
  tx = guMtxRowCol (src, 0, 1);
  ty = guMtxRowCol (src, 1, 1);
  tz = guMtxRowCol (src, 2, 1);
  guMtxCopy (src, dst);
  guMtxRowCol (dst, 0, 1) = guMtxRowCol (src, 0, 2);
  guMtxRowCol (dst, 1, 1) = guMtxRowCol (src, 1, 2);
  guMtxRowCol (dst, 2, 1) = guMtxRowCol (src, 2, 2);
  guMtxRowCol (dst, 0, 2) = tx;
  guMtxRowCol (dst, 1, 2) = ty;
  guMtxRowCol (dst, 2, 2) = tz;
}
Ejemplo n.º 2
0
void
cubemap_cam_matrix_for_face (Mtx cam, scene_info *scene, int face)
{
  Mtx rot;
  /*guPerspective (proj, 90, 1.0f, near, far);*/

  scene_update_camera (scene);
  
  switch (face)
    {
    case 0:  /* left */
      guMtxRotRad (rot, 'y', M_PI / 2);
      guMtxConcat (rot, scene->camera, cam);
      break;

    case 1:  /* front */
      guMtxCopy (scene->camera, cam);
      break;

    case 2:  /* right */
      guMtxRotRad (rot, 'y', -M_PI / 2);
      guMtxConcat (rot, scene->camera, cam);
      break;

    case 3:  /* back */
      guMtxRotRad (rot, 'y', M_PI);
      guMtxConcat (rot, scene->camera, cam);
      break;

    case 4:  /* top */
      guMtxRotRad (rot, 'x', -M_PI / 2);
      guMtxConcat (rot, scene->camera, cam);
      break;

    case 5:  /* bottom */
      guMtxRotRad (rot, 'x', M_PI / 2);
      guMtxConcat (rot, scene->camera, cam);
      break;
    }
}
Ejemplo n.º 3
0
void  glPushMatrix (void){
	guMtxCopy(model, _mtxelements[_mtxcurrentelement]);
	_mtxcurrentelement++;
}
Ejemplo n.º 4
0
void  glPopMatrix (void){
	_mtxcurrentelement--;
	guMtxCopy(_mtxelements[_mtxcurrentelement], model);
}
Ejemplo n.º 5
0
void Particle_Render(Mtx M_view, ParticleSystem* psystem, Camera* camera) {
	// setup TEV
	GX_ClearVtxDesc();
	
	GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
	GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT);
    GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);

	GX_SetVtxAttrFmt(GX_VTXFMT6, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
    GX_SetVtxAttrFmt(GX_VTXFMT6, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
	GX_SetVtxAttrFmt(GX_VTXFMT6, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);

	// load model-view matrix
	Mtx M_modelView;
	guMtxIdentity(M_modelView);
	GX_LoadPosMtxImm(M_modelView, GX_PNMTX0);

	// setup tev
	GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
	GX_SetAlphaUpdate(GX_TRUE);

	GX_SetNumChans(1);

	GX_SetTevColorIn( 
		GX_TEVSTAGE0, 
		GX_CC_TEXC,  // a
		GX_CC_RASC,  // b
		GX_CC_TEXA,  // c 
		GX_CC_ZERO); // d

	GX_SetTevColorOp(
		GX_TEVSTAGE0,	// stage
		GX_TEV_ADD,		// op
		GX_TB_ZERO,		// bias
		GX_CS_SCALE_2,	// scale
		GX_ENABLE,		// clamp 0-255
		GX_TEVPREV);	// output reg


	GX_SetTevAlphaIn(
		GX_TEVSTAGE0, 
		GX_CA_ZERO,  // a
		GX_CA_TEXA,  // b
		GX_CA_RASA,  // c 
		GX_CA_ZERO); // d

	GX_SetTevAlphaOp(
		GX_TEVSTAGE0,	// stage
		GX_TEV_ADD,		// op
		GX_TB_ZERO,		// bias
		GX_CS_SCALE_1,	// scale
		GX_ENABLE,		// clamp 0-255
		GX_TEVPREV);	// output reg



	GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);

	GX_SetNumTexGens(1);
	GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);

	GX_LoadTexObj(&psystem->texture, GX_TEXMAP0);

	int n = psystem->n_particles;

	f32 texCoords[] = {
		0, 0,
		0, 1,
		1, 1,
		1, 0
	};

	GX_InvVtxCache();
	Vec3 camPos = camera->position();

	Mtx axisMtx;
	
	System::LogClear();
	
	Particle_Sort(M_view, psystem);

	GX_Begin(GX_QUADS, GX_VTXFMT6, n*4);
		for (int k = 0; k < n; k++) {
			int i = psystem->binsAllocations[k].particleIdx;
			//System::Log(L"p%d", i);
			Vec3& p  = psystem->positions[i];
			f32 lifetime = psystem->lifetimes[i];
			f32 age = psystem->ages[i];

			f32 ratio = age/lifetime;

			Vec3 forward = Math3D::normalized(camPos - p);

			Vec3 worldUp = Vec3(0, 1, 0);
			Vec3 right = Math3D::normalized(Math3D::cross(worldUp, forward));

			Vec3 up = Math3D::cross(forward, right);

			Mtx pm;

			guMtxCopy(M_view, pm);
			guMtxTranspose(pm, pm);
			pm[0][3] = p.x;		pm[1][3] = p.y;		pm[2][3] = p.z;

			guMtxConcat(M_view, pm, pm);
			
			f32 rotation = psystem->rotations[i];
			if (psystem->rotationInterpolator)
				rotation = psystem->rotationInterpolator->getValue(rotation, ratio);

			f32 size = psystem->sizes[i];
			if (psystem->sizeInterpolator)
				size = psystem->sizeInterpolator->getValue(size, ratio);

			if (psystem->colorInterpolator)
				psystem->colors[i] = psystem->colorInterpolator->getValue(ratio);

			Matrix34 M_rot = Math3D::matrixRotationZ(rotation);
			f32 hs = size*0.5f;
			Vec3 p0(-hs, +hs, 0);
			Vec3 p1(-hs, -hs, 0);
			Vec3 p2(+hs, -hs, 0);
			Vec3 p3(+hs, +hs, 0);

			Vec3 vs[4] = {p0, p1, p2, p3};

			for (int i = 0; i < 4; i++) {
				vs[i] = M_rot * vs[i];
				vs[i] = Math3D::matrixVecMul(pm, vs[i]);
			}
			
			for (int i = 0; i < 4; i++) {
				f32* coords = &texCoords[2*i];
				SendVertex(vs[i], psystem->colors[i], coords[0], coords[1]);
			}
		}
	GX_End();


	return;
}
Ejemplo n.º 6
0
void gdl::Font::DrawText(const char *text, short x, short y, float scale, u_int col) {

    float	tx;
    GXColor textCol;
    Mtx		tempMatrix;


    if (vList == NULL)
        return;

    if (tList == NULL)
        return;


    if ((x == gdl::Centered) || (x == gdl::PCentered)) {
        tx = gdl::ScreenCenterX-((gdl::Font::CalcStrLen(text)*scale)/2)+(scale/2);
    } else {
        tx = x;
    }


    textCol.r = RED(col);
    textCol.g = GREEN(col);
    textCol.b = BLUE(col);
    textCol.a = ALPHA(col);

    GX_LoadTexObj(gdl::Font::charSheet.TexObj(), GX_TEXMAP0);
    GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);

    GX_ClearVtxDesc();
    GX_SetVtxDesc(GX_VA_POS, GX_INDEX16);
    GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX16);

    GX_SetArray(GX_VA_POS, gdl::Font::vList, 2*sizeof(s16));
    GX_SetArray(GX_VA_TEX0, gdl::Font::tList, 2*sizeof(f32));

    GX_SetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_VTX, GX_SRC_REG, 0, GX_DF_NONE, GX_AF_NONE);
    GX_SetChanMatColor(GX_COLOR0A0, textCol);


    guMtxCopy(gdl::wii::ModelMtx, tempMatrix);
    guMtxApplyTrans(tempMatrix, tempMatrix, tx, y, 0);
    guMtxApplyScale(tempMatrix, tempMatrix, scale, scale, 0);
    GX_LoadPosMtxImm(tempMatrix, GX_PNMTX0);


    for(int i=0; text[i]!=0x00; i++) {

        int tc=4*((u_char)text[i]);

        GX_Begin(GX_QUADS, GX_VTXFMT0, 4);

        GX_Position1x16(tc);
        GX_TexCoord1x16(tc);

        GX_Position1x16(tc+1);
        GX_TexCoord1x16(tc+1);

        GX_Position1x16(tc+2);
        GX_TexCoord1x16(tc+2);

        GX_Position1x16(tc+3);
        GX_TexCoord1x16(tc+3);

        GX_End();

        guMtxApplyTrans(tempMatrix, tempMatrix, gdl::Font::charWidth[(u_char)text[i]], 0, 0);
        GX_LoadPosMtxImm(tempMatrix, GX_PNMTX0);

    }

    GX_LoadPosMtxImm(gdl::wii::ModelMtx, GX_PNMTX0);
    GX_SetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_VTX, GX_SRC_VTX, 0, GX_DF_NONE, GX_AF_NONE);

}
Ejemplo n.º 7
0
void gdl::FFont::DrawText(const char *text, short x, short y, float scale, u32 col) {

    // Draws text using the current font set by gdl_SetCurrentFont()

    float	tx;
    int		c,tc;
    Mtx		TempMatrix;
    GXColor	TempCol;


    if (vList == NULL)
        return;


    if ((x == gdl::Centered) || (x == gdl::PCentered)) {
        tx = gdl::ScreenCenterX - ((((cw+1)*strlen(text))*scale)/2)+(scale/2);
    } else {
        tx = x;
    }

    TempCol.r = RED(col);
    TempCol.g = GREEN(col);
    TempCol.b = BLUE(col);
    TempCol.a = ALPHA(col);


    GX_LoadTexObj(charTexObj, GX_TEXMAP0);
    GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE);

    GX_ClearVtxDesc();
    GX_SetVtxDesc(GX_VA_POS, GX_INDEX8);
    GX_SetVtxDesc(GX_VA_TEX0, GX_INDEX16);

    GX_SetArray(GX_VA_POS, vList, 2*sizeof(s16));
    GX_SetArray(GX_VA_TEX0, tList, 2*sizeof(f32));


    guMtxCopy(gdl::wii::ModelMtx, TempMatrix);
    guMtxApplyTrans(TempMatrix, TempMatrix, tx, y, 0);
    guMtxApplyScale(TempMatrix, TempMatrix, scale, scale, 0);
    GX_LoadPosMtxImm(TempMatrix, GX_PNMTX0);

    GX_SetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_VTX, GX_SRC_REG, 0, GX_DF_NONE, GX_AF_NONE);
    GX_SetChanMatColor(GX_COLOR0A0, TempCol);

    for(c=0; text[c] != 0x00; c++) {

        tc = 4*((u_char*)text)[c];

        GX_Begin(GX_QUADS, GX_VTXFMT0, 4);

        GX_Position1x8(0);
        GX_TexCoord1x16(tc);

        GX_Position1x8(1);
        GX_TexCoord1x16(tc+1);

        GX_Position1x8(2);
        GX_TexCoord1x16(tc+2);

        GX_Position1x8(3);
        GX_TexCoord1x16(tc+3);

        GX_End();

        guMtxApplyTrans(TempMatrix, TempMatrix, cw+1, 0, 0);
        GX_LoadPosMtxImm(TempMatrix, GX_PNMTX0);

    }

    GX_LoadPosMtxImm(gdl::wii::ModelMtx, GX_PNMTX0);
    GX_SetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_VTX, GX_SRC_VTX, 0, GX_DF_NONE, GX_AF_NONE);

}