 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Fri Jan 06, 2006 1:24 am Post subject: faces over vertices, 'smart' sceGumDrawArray? |
|
|
hello, i am still strugglin' with my code,
what i am thinking about is i got the list of vertices that are in a mesh
and i got the faces (actually an array of short int which holds the position of the vertices for a trianlge)
so one face might look like this:
3 2 4
triangle #3 #2 #4
further i pass those values like
| Code: | | sceGumDrawArray(GU_TRIANGLES,GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,number_of_faces*3,faces,vertices); |
am i trying something that is not possible?
greets
lumo _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
memon
Joined: 03 Oct 2005 Posts: 63
|
Posted: Fri Jan 06, 2006 7:51 am Post subject: |
|
|
You are missing something :) The pspgu.h is at the moment the best documentation there is to this stuff.
sceGumDrawArray(GU_TRIANGLES,GU_INDEX_16BIT|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,number_of_faces*3,faces,vertices); |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Fri Jan 06, 2006 8:30 pm Post subject: |
|
|
true, forgot that, but still no go...
i pasted my code online now... (will be open source anyway, when its running...)
you can access/read my code here or read it in this thread
here you can download the files:
mymeshtest.cpp
Makefile
test.3db
| Code: | #include <pspkernel.h>
#include <pspiofilemgr.h> //new
#include <malloc.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <pspgu.h>
#include <pspgum.h>
PSP_MODULE_INFO("3D Mesh Test", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
#define printf pspDebugScreenPrintf
#define BUF_WIDTH (512)
#define SCR_WIDTH (480)
#define SCR_HEIGHT (272)
#define PIXEL_SIZE (4) /* change this if you change to another screenmode */
#define FRAME_SIZE (BUF_WIDTH * SCR_HEIGHT * PIXEL_SIZE)
#define ZBUF_SIZE (BUF_WIDTH SCR_HEIGHT * 2) /* zbuffer seems to be 16-bit? */
/* PSP-REPRESENTATION OF A POINT */
struct Vertex
{
//float u, v; // UV-texture
unsigned int color;// = 0xff7f0000; //static AABBGGRR
float x,y,z;
};
struct Point
{
float x,y,z;
};
/*
struct Vector
{
float x,y,z;
};
inline Vector Normalize( Vector &v )
{
float temp = 1/Length( v );
v.x *= temp;
v.y *= temp;
v.z *= temp;
return( v );
}
//calculate normal verctor and normalize it
inline Vector CrossProduct( Vector &v1, Vector &v2 )
{
Vector v;
v.x = ( v1.y * v2.z ) – ( v1.z * v2.y );
v.y = ( v1.z * v2.x ) – ( v1.x * v2.z );
v.z = ( v1.x * v2.y ) – ( v1.y * v2.x );
return Normalize( &v );
}
*/
static unsigned int __attribute__((aligned(16))) list[262144];
unsigned short __attribute__((aligned(16))) *faces;
struct Point __attribute__((aligned(16))) *points;
struct Vertex __attribute__((aligned(16))) *vertices;
struct Vertex __attribute__((aligned(16))) *vertex_render_list;
// add coloredpoints at v2
int SetupCallbacks();
int main(int argc, char* argv[])
{
SceCtrlData pad;
unsigned long number_of_vertices;
unsigned long number_of_faces;
int version;
SetupCallbacks();
// load model
//printf("Loading 3D-Model...\n", number_of_vertices);
FILE *fd = fopen("ms0:/PSP/test.3db","rb");
fseek(fd, 3, SEEK_CUR); // '3', 'D', 'B'
fread((void*)&number_of_vertices, sizeof(unsigned long),1,fd); // vertices count
fread((void*)&number_of_faces, sizeof(unsigned long),1,fd); // faces count
fread((void*)&version, sizeof(int),1,fd); // version of 3D-Binary mesh
//points=memalign(16,sizeof(float)*number_of_vertices*3);
points=(struct Point*)memalign(16,sizeof(struct Point*)*number_of_vertices/3);
vertices=(struct Vertex*)memalign(16,sizeof(struct Vertex)*number_of_vertices);
fread((void*)points, sizeof(struct Point),number_of_vertices,fd);
//printf("number_of_vertices = %i\n", number_of_vertices);
//printf("number_of_faces = %i\n", number_of_faces);
// load the points to the vertices (u,v is set to zero, color is fixed in v1)
for (unsigned int i=0; i <= number_of_vertices; i++)
{
//vertices[i].u = 0.0;
//vertices[i].v = 0.0;
vertices[i].color = 0xff7f0000;
vertices[i].x = points[i].x;
vertices[i].y = points[i].y;
vertices[i].z = points[i].z;
}
free(points);
sceKernelDcacheWritebackAll();
// load the faces
faces=(unsigned short*)memalign(16,sizeof(unsigned short)*number_of_faces*3);
fread((void*)faces, sizeof(unsigned short),number_of_faces*3,fd);
// faces hold the number of vertices...
sceKernelDcacheWritebackAll();
fclose(fd);
// setup ctrl
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
float rx = 0;
float ry = 0;
float rz = 0;
float pz = -20;
float px = 0;
// setup GU
sceGuInit();
sceGuStart(GU_DIRECT,list);
sceGuDrawBuffer(GU_PSM_8888,(void*)0,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(0xc350,0x2710);
sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
sceGuEnable(GU_SCISSOR_TEST);
sceGuDepthFunc(GU_GEQUAL);
sceGuEnable(GU_DEPTH_TEST);
sceGuFrontFace(GU_CCW);
sceGuShadeModel(GU_SMOOTH);
sceGuEnable(GU_CULL_FACE);
sceGuEnable(GU_TEXTURE_2D);
sceGuEnable(GU_CLIP_PLANES);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuDisplay(GU_TRUE);
// run sample
for(;;)
{
sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons & PSP_CTRL_CIRCLE) break;
sceGuStart(GU_DIRECT,list);
// clear screen
sceGuClearColor(0xff000000);
sceGuClearDepth(0);
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
// setup matrices for cube
sceGumMatrixMode(GU_PROJECTION);
sceGumLoadIdentity();
sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);
sceGumMatrixMode(GU_VIEW);
sceGumLoadIdentity();
sceGumMatrixMode(GU_MODEL);
sceGumLoadIdentity();
if (127-pad.Ly>50) rx+=((127-pad.Ly)-50) * 0.04f;
if (127-pad.Ly<-50) rx+=((127-pad.Ly)+50) * 0.04f;
if (127-pad.Lx>50) ry+=((127-pad.Lx)-50) * 0.04f;
if (127-pad.Lx<-50) ry+=((127-pad.Lx)+50) * 0.04f;
if(pad.Buttons & PSP_CTRL_SQUARE)
{
//other cmds
}
else
{
if(pad.Buttons & PSP_CTRL_LTRIGGER) rz-=1.0f;
if(pad.Buttons & PSP_CTRL_RTRIGGER) rz+=1.0f;
if(pad.Buttons & PSP_CTRL_UP) pz/=1.05f;
if(pad.Buttons & PSP_CTRL_DOWN) pz*=1.05f;
if(pad.Buttons & PSP_CTRL_LEFT) px-=0.1f;
if(pad.Buttons & PSP_CTRL_RIGHT) px+=0.1f;
}
ScePspFVector3 pos = { px, 0, pz };
ScePspFVector3 rot = { rx * 1.00f * (M_PI/180.0f), ry * 1.00f * (M_PI/180.0f), rz * (M_PI/180.0f)};
sceGumRotateXYZ(&rot);
sceGumTranslate(&pos);
// draw cube
//sceGumDrawArray(GU_TRIANGLES,GU_INDEX_16BIT|GU_TEXTURE_32BITF|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,number_of_faces*3,faces,vertices);
sceGumDrawArray(GU_TRIANGLES,
GU_INDEX_16BIT|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,
number_of_faces*3,
faces,
vertices);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
}
sceGuTerm();
sceKernelExitGame();
return 0;
}
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
|
the makefile is like:
| Code: | TARGET = mymeshtest
OBJS = mymeshtest.o
INCDIR =
CFLAGS = -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
LIBS= -lpspgum -lpspgu -lm
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = 3dloadtest
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
|
_________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
ufoz
Joined: 10 Nov 2005 Posts: 86 Location: Tokyo
|
Posted: Sat Jan 07, 2006 12:21 pm Post subject: |
|
|
You should disable GU_TEXTURE_2D if you're not using a texture.
As for the cache writeback, since your mesh data doesn't change each frame, theoretically it should be enough to flush the cache only once, after you're done loading your model. (but maybe someone can correct me if I'm wrong) |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Sat Jan 07, 2006 9:39 pm Post subject: |
|
|
ok i removed the 2d-texture and the chachewritebacks...
still the same... app crashes...
hum possibly i found the bug... (omg, yes! its in the loadin' part *outch*)
it crashes in line: free(points);
but WHY?
greets
lumo _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Sat Jan 07, 2006 9:49 pm Post subject: |
|
|
Usually happens because you've overwritten the end of the allocation by mistake...
| Code: |
points=(struct Point*)memalign(16,sizeof(struct Point*)*number_of_vertices/3);
...
fread((void*)points, sizeof(struct Point),number_of_vertices,fd);
|
Aye Caramba!
Are you sure that shouldn't be
| Code: |
points=(struct Point*)memalign(16,sizeof(struct Point)*number_of_vertices);
|
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Sat Jan 07, 2006 9:54 pm Post subject: |
|
|
you are right, thats another mistake by me :)
but still the same, fucks up at free(points);
note: even if i remove the free line program fucks up at psp...
greets
lumo
PS: i changed it so i can execute it on my computer and just printf the stuff...
| Code: | printf("freein' points... ");
free(points); //FUCKS UP THE PROGRAM, WHY?
printf("done.\n"); |
program output at this part is:
| Quote: |
$ testload.exe
:number_of_vertices = 8
:number_of_faces = 12
freein' points...
Home@lumo ~/ |
_________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Sat Jan 07, 2006 10:37 pm Post subject: |
|
|
| Code: |
vertices=(struct Vertex*)memalign(16,sizeof(struct Vertex)*number_of_vertices);
...
for (unsigned int i=0; i <= number_of_vertices; i++)
|
One out here too...
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Sat Jan 07, 2006 11:24 pm Post subject: |
|
|
ok i now took out the loading part to have a look at it alone...
after some testing i found something strange...
first:
load the points to memory -> fine (test per output)
| Code: | for (unsigned int i=0; i < number_of_vertices; i++)
{
printf("{%f, %f, %f},\n", points[i].x, points[i].y, points[i].z);
} |
the line below (note: NO code between...)
| Code: | for (unsigned int i=0; i < number_of_vertices; i++)
{
vertices[i].u = 0.0;
vertices[i].v = 0.0;
vertices[i].color = 0xff7f0000;
vertices[i].x = points[i].x;
vertices[i].y = points[i].y;
vertices[i].z = points[i].z;
}
for (unsigned int i=0; i < number_of_vertices; i++)
{
printf("{%f, %f, %u, %f, %f, %f},\n", vertices[i].u, vertices[i].v, vertices[i].color, vertices[i].x, vertices[i].y, vertices[i].z);
}
|
and now the misterious part!
vertices do NOT hold the values from above!
ok they do for the first 12values but after those, they are fucked up...
code and output, displayed on cmd
last but not least the src, that should be in memory _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Sat Jan 07, 2006 11:37 pm Post subject: |
|
|
This is STILL wrong
| Code: |
points=(struct Point*)memalign(16,sizeof(struct Point*)*number_of_vertices);
|
It should be
| Code: | points=(struct Point*)memalign(16,sizeof(struct Point)*number_of_vertices);
|
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Sat Jan 07, 2006 11:53 pm Post subject: |
|
|
great!
its no more crashing, although the result is not what i expected :D
the loaded mesh is no cube...
possibly the index starts at 0 not at 1 as i did it...
going to figure that out...
if some one knows for sure, let me know
EDIT: i was right, had to decrease the indices per one, so starts at zero, works fine now although it looks bit stretched...
values are proper so it must be correct :D
THANKS for your great support!
greets
lumo _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|