true, forgot that, but still no go...
i pasted my code online now... (will be open source anyway, when its running...)
Code: Select all
#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;
}