need help with some guTranslate problem

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Heimdall
Posts: 245
Joined: Thu Nov 10, 2005 1:29 am
Location: Netherlands
Contact:

need help with some guTranslate problem

Post by Heimdall »

I've a simple piece of code:

Code: Select all

	fbp0  = 0;

	// Init GU
	sceGuInit();
	sceGuStart(GU_DIRECT, display_list);

	// Set Buffers
	sceGuDrawBuffer(GU_PSM_8888, fbp0, BUF_WIDTH);
	sceGuDispBuffer(SCR_WIDTH, SCR_HEIGHT, (void*)0x88000, BUF_WIDTH);
	sceGuDepthBuffer((void*)0x110000, BUF_WIDTH);

	sceGuOffset(2048 - (SCR_WIDTH/2), 2048 - (SCR_HEIGHT/2));
	sceGuViewport(2048, 2048, SCR_WIDTH, SCR_HEIGHT);
	sceGuDepthRange(65535, 0);

	// Set Render States
	// Enable scissor test, depth test, smooth shading and culling
	sceGuScissor(0, 0, SCR_WIDTH, SCR_HEIGHT);
	sceGuEnable(GU_SCISSOR_TEST);
	sceGuDepthFunc(GU_GEQUAL);
	sceGuEnable(GU_DEPTH_TEST);
	sceGuShadeModel(GU_SMOOTH);
	sceGuFrontFace(GU_CCW);
	sceGuEnable(GU_CULL_FACE);
	sceGuEnable(GU_CLIP_PLANES);

	// set clear color/depth
	sceGuClearColor( GU_COLOR( 0.0f, 0.0f, 0.0f, 1.0f ) );
	sceGuClearDepth(0);

	// setup texture
	sceGuEnable(GU_TEXTURE_2D);		            //Enable Texture2D
	sceGuTexFunc(GU_TFX_MODULATE, GU_TCC_RGB);
	sceGuTexFilter(GU_LINEAR, GU_LINEAR);		// Linear filtering
	sceGuTexScale(1.0f, 1.0f);                  // No scaling
	sceGuTexOffset(0.0f, 0.0f);

	sceGuFinish();
	sceGuSync(0,0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);
	// finish

	// setup projection matrix
	sceGumMatrixMode(GU_PROJECTION);
	sceGumLoadIdentity();
	sceGumPerspective(fov, aspect, znear, zfar);

	// look at
	sceGumMatrixMode(GU_VIEW);
	sceGumLoadIdentity();
	sceGumLookAt(eye, center, up);
	
	// io
	sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
	
	Model* model = loadModel();
	
	while(1) {
		// begin
		sceGuStart(GU_DIRECT, display_list);
		sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
		
		// peek
		sceCtrlPeekBufferPositive(&pad, 1);
		
		// update x and y
		model->position->x = (float) (pad.Lx - 128);
		model->position->y = (float) (pad.Ly - 128);

		// texture bind
		sceGuColor(GU_COLOR(1.0f,1.0f,1.0f,0.0f));
		sceGuTexMode(model->texture->mode, 0, 0, 1);
		sceGuTexImage(0,
				model->texture->width,
				model->texture->height,
				model->texture->width,
				model->texture->pixels);
		
		sceGumMatrixMode(GU_MODEL);
                // i should see the model to go left and right, top down, right? why doesn't it work?
		sceGumTranslate(model->position));
		sceGumLoadMatrix(model->initialTransform));

		// draw mesh
		sceGumDrawArray(
			GU_TRIANGLES,
			model->mesh->vtype | GU_TRANSFORM_3D,
			model->mesh->nFaces * 3,
			model->mesh->indices,
			model->mesh->vertices);

		// end
		sceGuFinish();
		sceGuSync(0, 0);
		
		// swap buffers
		fbp0 = sceGuSwapBuffers();
	}
And I was trying to use the analog stick to translate my mesh on the x, y axys but i cannot see anything happening.

The model is rendered and the texture also but the translation doesn't seem to work, I'm doing something wrong for sure, can anyone show me what?

Thanks!
jsharrad
Posts: 100
Joined: Thu Oct 20, 2005 3:06 am

Post by jsharrad »

Looks like you're overwriting the current translated matrix with model->initialTransform before you draw the model.
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

Something like this may help:

Code: Select all

sceGumMatrixMode(GU_MODEL);
sceGumLoadMatrix(model->initialTransform);
sceGumPushMatrix();
sceGumTranslate(model->position); 

// draw mesh 
sceGumDrawArray( 
    GU_TRIANGLES, 
    model->mesh->vtype | GU_TRANSFORM_3D, 
    model->mesh->nFaces * 3, 
    model->mesh->indices, 
    model->mesh->vertices);

sceGumPopMatrix();
Heimdall
Posts: 245
Joined: Thu Nov 10, 2005 1:29 am
Location: Netherlands
Contact:

Post by Heimdall »

yeap that was it, thanks!
Post Reply