Some basic 3D stuff

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
Quzar
Dream Coder
Dream Coder
Posts: 7497
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Wed Jul 31, 2002 12:14 am
Location: Miami, FL
Has thanked: 4 times
Been thanked: 9 times
Contact:

Some basic 3D stuff

Post by Quzar »

I'm trying to take a texture that normally takes up the whole screen, and make it tilt depending on user input (sort of like the character selection/options/etc screens in ssb:m with the C stick).

The way I've tried to do it so far is to get the y axis from the analog stick , multiply it by 0.01f and add it to the z value for the top two vertices then subtract it from the z values of the bottom two verticies (making sure the z value starts in a middle position).

This doesn't get the desired effect though. What am I doing wrong?

Code: Select all

float	z1	=2.56001f;						//Z depth of each vertex	//1.28*2 + a little?
float	zy  =0.0f;							//The amount of y tilt.
float	zx	=0.0f;							//The amount of x tilt.

...

void tilty(signed short int tilt)	//Takes a number between -128 -16 and 16 128
{	
	zy = tilt*0.01f;	//between -1.28f and 1.28f
}

...

void blit(void) { 

	pvr_poly_hdr_t hdr; 
	pvr_vertex_t vert; 
	pvr_poly_cxt_t cxt; 

#ifdef PALETTE
	pvr_txr_load_ex(vidram_buf, vidram_tex, 256,256, PVR_TXRLOAD_8BPP);	//Send buffer to texture and swiz it up.
#else
	pvr_txr_load(vidram_buf, vidram_tex, sizeofbuf);	//Send buffer to texture
#endif

	pvr_wait_ready();
	pvr_scene_begin();
    
	pvr_list_begin(PVR_LIST_OP_POLY); 
#ifdef PALETTE
	pvr_poly_cxt_txr(&cxt, PVR_LIST_OP_POLY, PVR_TXRFMT_PAL8BPP, 256,256, vidram_tex, 0); 
#else
	pvr_poly_cxt_txr(&cxt, PVR_LIST_OP_POLY, PVR_TXRFMT_RGB565|PVR_TXRFMT_NONTWIDDLED, 256,256, vidram_tex, 0); 
#endif
	pvr_poly_compile(&hdr, &cxt); 

	pvr_prim(&hdr, sizeof(hdr)); 

	vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f);    
	vert.oargb = 0; 
	vert.flags = PVR_CMD_VERTEX; 
    
	/* Top left */
	vert.x = X1; 
	vert.y = Y1; 
	vert.z = z1+zy; 
	vert.u = u1; 
	vert.v = v1; 
	pvr_prim(&vert, sizeof(vert)); 
	    
	/* Top right */
	vert.x = X1+w; 
	vert.y = Y1; 
	vert.z = z1+zy; 
	vert.u = u2; 
	vert.v = v1; 
	pvr_prim(&vert, sizeof(vert)); 
    
	/* Bottom left */
	vert.x = X1; 
	vert.y = Y1+h; 
	vert.z = z1-zy; 
	vert.u = u1; 
	vert.v = v2; 
	pvr_prim(&vert, sizeof(vert)); 
    
	/* Bottom right */
	vert.x = X1+w; 
	vert.y = Y1+h; 
	vert.z = z1-zy; 
	vert.u = u2; 
	vert.v = v2; 
	vert.flags = PVR_CMD_VERTEX_EOL; 
	pvr_prim(&vert, sizeof(vert)); 

	pvr_list_finish(); 
	pvr_scene_finish();

} 
I'm fairly ignorant as to how the 3D works (or how 3D in general does things) so any pointers would be appreciated.
"When you post fewer lines of text than your signature, consider not posting at all." - A Wise Man
Phantom
DC Developer
DC Developer
Posts: 1753
Joined: Thu Jan 16, 2003 4:01 am
Location: The Netherlands
Has thanked: 0
Been thanked: 0
Contact:

Post by Phantom »

If you use the PVR API you won't get automatic "depth perception" by using different Z values. Taking a simple square as an example: you can make something appear in front or behind of something else, but the PVR won't make it smaller/bigger for you. You'll need to calculate that manually and adjust the x and y coordinates accordingly.

It's easier to just use KGL.
Last edited by Phantom on Mon Nov 06, 2006 5:13 pm, edited 1 time in total.
"Nothing works" - Catweazle
User avatar
Quzar
Dream Coder
Dream Coder
Posts: 7497
Joined: Wed Jul 31, 2002 12:14 am
Location: Miami, FL
Has thanked: 4 times
Been thanked: 9 times
Contact:

Post by Quzar »

oh poo. so i actually have to do something maybe like a trig calculation on the x/y based on an imaginary circle that it's rotating about?

also, the stretching I get is doing some sort of depth perception thing, but just not the right way.
"When you post fewer lines of text than your signature, consider not posting at all." - A Wise Man
Phantom
DC Developer
DC Developer
Posts: 1753
Joined: Thu Jan 16, 2003 4:01 am
Location: The Netherlands
Has thanked: 0
Been thanked: 0
Contact:

Post by Phantom »

The only example I know of that does 3D using the PVR API directly is the 2nd mix demo. It's part of the KOS examples. That may be of some help.

EDIT: The stretching is caused by the PVR applying depth to the texture image. But it won't project the vertices for you. They will remain at the (x, y) locations you specified. That's probably the weird stretching effect you're seeing now.
"Nothing works" - Catweazle
User avatar
showka
DCEmu Freak
DCEmu Freak
Posts: 95
Joined: Fri Nov 23, 2001 12:01 pm
Location: Border Town
Has thanked: 0
Been thanked: 0
Contact:

Post by showka »

Hey Phantom, I'm pretty bad at Math. For awhile now, I've been attemtping to use the PVR functions directly to do some 3D stuff, but I can't seem to get my projection equations to be perfect. Do you know of any good tutorial / example / resource etc that shows a good, simple projection equation, especially one that would be analogous to what KGL does?

I'm using the PVR mainly for 2D so I'm avoiding using KGL.
Phantom
DC Developer
DC Developer
Posts: 1753
Joined: Thu Jan 16, 2003 4:01 am
Location: The Netherlands
Has thanked: 0
Been thanked: 0
Contact:

Post by Phantom »

Wikipedia has an article on 3D projection: http://en.wikipedia.org/wiki/3d_projection
"Nothing works" - Catweazle
Post Reply