How to correctly align vertices?

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

Moderators: cheriff, TyRaNiD

Post Reply
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

How to correctly align vertices?

Post by Ghoti »

Hi folks,

I'm trying to draw an object correctly, i don't really get it correct and i guess it is because i have not aligned the vertices because i really dont know exactly how to do it. How someone can explain them a little bit.

All the vertices are stored this way:

Code: Select all

typedef struct { float			u, v; 
					 unsigned int			color;
					 float			x, y, z; } ObjVertexB;	// vertex to render

	typedef struct { unsigned int	iNumberOfVertices;
					 ObjVertexB		*Vertices; } ObjStrip;

	typedef struct _MeshB {	unsigned int	iNumberOfStrips;
							ObjStrip		*Strips; } MeshB;
so my mesh has strips and those strips have the vertices however this way the vertices are not aligned.

i create them using this code:

Code: Select all

tmpObj->iNumberOfStrips = tmpStrips;
		tmpObj->Strips = (ObjStrip*)malloc(tmpStrips * sizeof(ObjStrip));
tmpObj->Strips[iStripNr].iNumberOfVertices = tmpStripsSize[iStripNr];
		tmpObj->Strips[iStripNr].Vertices = (ObjVertexB*)malloc(tmpStripsSize[iStripNr] * sizeof(ObjVertexB));
i then draw it like this:

Code: Select all

tmpObj->Strips[iStripNr].iNumberOfVertices = tmpStripsSize[iStripNr];
		tmpObj->Strips[iStripNr].Vertices = (ObjVertexB*)malloc(tmpStripsSize[iStripNr] * sizeof(ObjVertexB));
		
Hope someone can help me implement the alignment

greets ghoti
zoret
Posts: 22
Joined: Sun Mar 19, 2006 7:57 pm

Post by zoret »

to allocate aligned on 16b you can use the memalign function
so :

ObjVertexB * pVertices = memalign(16, nbVertices * sizeof(ObjVertexB));

maybe you can help to use psplink ! ;)
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

malloc on psp is aligned to 16byte by default.

There's nothing generally wrong with the code, if the drawing messes up, its more likely to other problems than the alignment, because wrong alignment would just crash the program.
<Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki

Alexander Berl
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

Hi thanks for the reply, however i have a question left:

i have used psplink it is very usefull for everything but there is one thing that is very annoying about psplink. for some reason psplink accepts some code while the psp on its own does not.

example:

with controls, if i use the analog pad this way:

Code: Select all

float movement;
movement = &#40;float&#41;&#40;pad.Lx&#41; - 128.0f;
if i run this through psplink i can move around, however when i run this the normal way as a pbp i can't move around.

other annoying things that happens are code that crashes the normal way but in psplink it is accepted. Last time i was quite far with some code and then i ran it the normal way and it crashed on several occasions.

why is this? is this because i am probebly not using the newest psptoolchain anymore?

greets ghoti
Tinnus
Posts: 67
Joined: Sat Jul 29, 2006 1:12 am

Post by Tinnus »

You need that to make the analog work:

Code: Select all

    sceCtrlSetSamplingCycle&#40;0&#41;;
    sceCtrlSetSamplingMode&#40;PSP_CTRL_MODE_ANALOG&#41;;
PSPLink probably does that itself, that's why your program can use it. IRShell does the same thing :)
Let's see what the PSP reserves... well, I'd say anything is better than Palm OS.
Ghoti
Posts: 288
Joined: Sat Dec 31, 2005 11:06 pm

Post by Ghoti »

Ah thanks that did the trick
Post Reply