Control responce slow

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

Moderators: cheriff, TyRaNiD

Post Reply
wacco
Posts: 3
Joined: Wed Aug 24, 2005 8:16 am

Control responce slow

Post by wacco »

Hi there,

I've recently started fiddling around with the pspsdk, and ran into a little trouble. When I'm combining code from the examples cube.c (gu/cube) and controller.c (controller/basic) the responce time of the input is extremely slow, or even none at all.
My source can be found here: http://www.jlpro.nl/wacco/cube.c
The main thing is the following line:
cursor_vertices[1].x = ((float) pad.Lx - 123);
Since I thought that the above was a little extreme, I did a divide by 10 first. Since that didn't seem to work I ended up with the above. Now, if you try really hard the vertex might change, but don't expect to much of it. Most of the time, it doesn't move at all.
If you replace that line with the following:
if(pad.Buttons != 0) {
if(pad.Buttons & PSP_CTRL_SQUARE) val2 = -2;
} else val2 = -1;
cursor_vertices[1].x = val2;
It does work, but extremely slow. Press the button, keep it pressed and wait... wait... wait... ah, there we go. Release it, wait... wait.. you get the idea.

Anybody has an idea what I'm doing wrong? The lights on the vertexes (comes from lights.c (gu/lights) btw) work fluently, and I'm kinda clueless.

Thanks :)
rinco
Posts: 255
Joined: Fri Jan 21, 2005 2:12 pm
Location: Canberra, Australia

Post by rinco »

Code: Select all

cursor_vertices[1].x = ((float) pad.Lx - 123);
Try multiplying pad.Lx by a float, instead of casting.
wacco
Posts: 3
Joined: Wed Aug 24, 2005 8:16 am

Post by wacco »

Solved it. Took a while, but that's mainly because I was busy doing other stuff. For completeness I explain what I did wrong (and the post above doesn't really make sence, nofi, but I hope you realised that yourself).

The main problem was that nobody told or gave a demo of how he/she did the trick in hardware (or at least with pspsdk functions) and the demo's which did do multiple objects parsed all the translations in software. I tried to change the vertices straight away which was stupid (I knew that) because I tried to avoid matrix calculations completely. Apparantly, your psp doesn't like that. :)

The trick is that sceGumTranslate() translates all the vertices drawn afterwards. It does this by fiddling around in the matrix which is set up, and when you're just drawing just one object it isn't a problem (that's what you want after all).
It gets trickier with two objects because the matrix is then altered, and your second object gets influenced. How to work around this? Use the matrix stack thingy *whatever*. Functions needed?

sceGumPushMatrix() and sceGumPopMatrix().

So, something like the following _will_ work:

Code: Select all

		sceGumPushMatrix();
			if(pad.Buttons != 0) 
				if(pad.Buttons & PSP_CTRL_SQUARE) 
					sceGumTranslate(&pos);

		sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,2*3,0,vertices);
		
		sceGumPopMatrix();
		sceGumPushMatrix();

			if(pad.Buttons != 0) 
				if(pad.Buttons & PSP_CTRL_CIRCLE) 
					sceGumTranslate(&pos2);
		
		sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,2*3,0,cursor_vertices);
		
		sceGumPopMatrix();
Now, this is my way of doing things and I don't know if there's a better way, but it works like a charm. Multiple objects, simple functions, sounds like a sweet solution to me.

People who'd like to see a running example, check http://www.jlpro.nl/wacco/cube.c (cube, lights, controller combined with two objects)
It's kinda sloppy and messy but that's because I was trying out multiple things at the same time. Just start screwing around with it like I'm doing.

Enjoy :)
User avatar
ReKleSS
Posts: 73
Joined: Sat Jun 18, 2005 12:57 pm
Location: Melbourne, Australia

Post by ReKleSS »

Heh... you've come up with the standard OpenGL approach to dealing with matrices :p Since the PSP 3d API is somewhat similar to OGL, you might want to read up on that...
-ReK
wacco
Posts: 3
Joined: Wed Aug 24, 2005 8:16 am

Post by wacco »

I did read up on that, I'm currently trying things in OpenGL / Glut. If it works, I try the same method on the psp. :P

Only thing I noticed is that the depth buffer gets screwed up in this way, maybe it's just something I did wrong or it's really the push/pop matrix that prevents this from working. Idunno, but whatever. I'll continue playing in OpenGL first. :)

Btw, does anybody know if there are functions like glutGet(GLUT_ELAPSED_TIME) in the pspsdk? Could really use that one...
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Re: Control responce slow

Post by holger »

wacco wrote:if(pad.Buttons != 0) {
if(pad.Buttons & PSP_CTRL_SQUARE) val2 = -2;
} else val2 = -1;
cursor_vertices[1].x = val2;
Try using latched events and investigate the Make/Break bits instead of the corresponding Button bits if you don't want to miss events between frames. See pspgl's glut.c for an example.
holger
Posts: 204
Joined: Thu Aug 18, 2005 10:57 am

Post by holger »

wacco wrote:Btw, does anybody know if there are functions like glutGet(GLUT_ELAPSED_TIME) in the pspsdk? Could really use that one...
what about gettimeofday()? You could easily implement glutGet(GLUT_ELAPSED_TIME) using this, see e.g. our Sys_Milliseconds() implementation in pspgl/test-q3/generic/main.c. If you implement a rough glutGet() providing the most commonly used functionalities... patches are welcome!
Post Reply