Custom model viewer based off cube sdk sample - help
Custom model viewer based off cube sdk sample - help
Hello, I am trying to use the cube example in the sdk as a base to create a viewer on the PSP. I eventually want to export out models from 3dsmax to the PSP. First, I am trying to get a basic understanding of what is happening in the sample:
I am assuming the cube is constructed with this:
struct Vertex __attribute__((aligned(16))) vertices[12*3] =
{
{0, 0, 0xff7f0000,-1,-1, 1}, // 0
{1, 0, 0xff7f0000,-1, 1, 1}, // 4
{1, 1, 0xff7f0000, 1, 1, 1}, // 5
{0, 0, 0xff7f0000,-1,-1, 1}, // 0
{1, 1, 0xff7f0000, 1, 1, 1}, // 5
{0, 1, 0xff7f0000, 1,-1, 1}, // 1
{0, 0, 0xff7f0000,-1,-1,-1}, // 3
{1, 0, 0xff7f0000, 1,-1,-1}, // 2
{1, 1, 0xff7f0000, 1, 1,-1}, // 6
{0, 0, 0xff7f0000,-1,-1,-1}, // 3
{1, 1, 0xff7f0000, 1, 1,-1}, // 6
{0, 1, 0xff7f0000,-1, 1,-1}, // 7
{0, 0, 0xff007f00, 1,-1,-1}, // 0
{1, 0, 0xff007f00, 1,-1, 1}, // 3
{1, 1, 0xff007f00, 1, 1, 1}, // 7
{0, 0, 0xff007f00, 1,-1,-1}, // 0
{1, 1, 0xff007f00, 1, 1, 1}, // 7
{0, 1, 0xff007f00, 1, 1,-1}, // 4
{0, 0, 0xff007f00,-1,-1,-1}, // 0
{1, 0, 0xff007f00,-1, 1,-1}, // 3
{1, 1, 0xff007f00,-1, 1, 1}, // 7
{0, 0, 0xff007f00,-1,-1,-1}, // 0
{1, 1, 0xff007f00,-1, 1, 1}, // 7
{0, 1, 0xff007f00,-1,-1, 1}, // 4
{0, 0, 0xff00007f,-1, 1,-1}, // 0
{1, 0, 0xff00007f, 1, 1,-1}, // 1
{1, 1, 0xff00007f, 1, 1, 1}, // 2
{0, 0, 0xff00007f,-1, 1,-1}, // 0
{1, 1, 0xff00007f, 1, 1, 1}, // 2
{0, 1, 0xff00007f,-1, 1, 1}, // 3
{0, 0, 0xff00007f,-1,-1,-1}, // 4
{1, 0, 0xff00007f,-1,-1, 1}, // 7
{1, 1, 0xff00007f, 1,-1, 1}, // 6
{0, 0, 0xff00007f,-1,-1,-1}, // 4
{1, 1, 0xff00007f, 1,-1, 1}, // 6
{0, 1, 0xff00007f, 1,-1,-1}, // 5
};
Since there are twelve faces in a cube, and I am guessing that each block of three lines is setting up the 3 verts for each face. My first question is what does each block mean? Are they x,y,x coordinates or some kind of matrix?
Also, I am not sure what the first line is doing, exactly. Is 16 the number of unique verts and 12 the number of faces? Why multiply them?
Thanks for any help!
I am assuming the cube is constructed with this:
struct Vertex __attribute__((aligned(16))) vertices[12*3] =
{
{0, 0, 0xff7f0000,-1,-1, 1}, // 0
{1, 0, 0xff7f0000,-1, 1, 1}, // 4
{1, 1, 0xff7f0000, 1, 1, 1}, // 5
{0, 0, 0xff7f0000,-1,-1, 1}, // 0
{1, 1, 0xff7f0000, 1, 1, 1}, // 5
{0, 1, 0xff7f0000, 1,-1, 1}, // 1
{0, 0, 0xff7f0000,-1,-1,-1}, // 3
{1, 0, 0xff7f0000, 1,-1,-1}, // 2
{1, 1, 0xff7f0000, 1, 1,-1}, // 6
{0, 0, 0xff7f0000,-1,-1,-1}, // 3
{1, 1, 0xff7f0000, 1, 1,-1}, // 6
{0, 1, 0xff7f0000,-1, 1,-1}, // 7
{0, 0, 0xff007f00, 1,-1,-1}, // 0
{1, 0, 0xff007f00, 1,-1, 1}, // 3
{1, 1, 0xff007f00, 1, 1, 1}, // 7
{0, 0, 0xff007f00, 1,-1,-1}, // 0
{1, 1, 0xff007f00, 1, 1, 1}, // 7
{0, 1, 0xff007f00, 1, 1,-1}, // 4
{0, 0, 0xff007f00,-1,-1,-1}, // 0
{1, 0, 0xff007f00,-1, 1,-1}, // 3
{1, 1, 0xff007f00,-1, 1, 1}, // 7
{0, 0, 0xff007f00,-1,-1,-1}, // 0
{1, 1, 0xff007f00,-1, 1, 1}, // 7
{0, 1, 0xff007f00,-1,-1, 1}, // 4
{0, 0, 0xff00007f,-1, 1,-1}, // 0
{1, 0, 0xff00007f, 1, 1,-1}, // 1
{1, 1, 0xff00007f, 1, 1, 1}, // 2
{0, 0, 0xff00007f,-1, 1,-1}, // 0
{1, 1, 0xff00007f, 1, 1, 1}, // 2
{0, 1, 0xff00007f,-1, 1, 1}, // 3
{0, 0, 0xff00007f,-1,-1,-1}, // 4
{1, 0, 0xff00007f,-1,-1, 1}, // 7
{1, 1, 0xff00007f, 1,-1, 1}, // 6
{0, 0, 0xff00007f,-1,-1,-1}, // 4
{1, 1, 0xff00007f, 1,-1, 1}, // 6
{0, 1, 0xff00007f, 1,-1,-1}, // 5
};
Since there are twelve faces in a cube, and I am guessing that each block of three lines is setting up the 3 verts for each face. My first question is what does each block mean? Are they x,y,x coordinates or some kind of matrix?
Also, I am not sure what the first line is doing, exactly. Is 16 the number of unique verts and 12 the number of faces? Why multiply them?
Thanks for any help!
Just a wild guess, but...
Box has 6 square shaped faces. You have 12 triangles defined (2 for each square)
Vertex table holds points (vertices) of each triangle corner (three points per triangle, 12 triangles = 12*3 vertices).
Values may be:
{u, v, color, x, y, z}
u, v: texture coordinates
color - color (0xAARRGGBB - alpha, red, green, blue)
x, y, z - position
Since I can understand this by seeing data only, it is highly possible you have no experience with 3D programming at all. Please read some stuff on 3D data representation before going any further. DirectX of OpenGL manuals would be nice.
Box has 6 square shaped faces. You have 12 triangles defined (2 for each square)
Code: Select all
+----+
| /|
| / |
| / |
|/ |
+----+
Values may be:
{u, v, color, x, y, z}
u, v: texture coordinates
color - color (0xAARRGGBB - alpha, red, green, blue)
x, y, z - position
Since I can understand this by seeing data only, it is highly possible you have no experience with 3D programming at all. Please read some stuff on 3D data representation before going any further. DirectX of OpenGL manuals would be nice.
thanks for the quick reply
I am amazind you guys respond so quickly. Thanks! I have a lot of experience with creating 3d content, and am in the process of learning 3d programming. I figure asking questions on an open forum is a good way to learn 3d programming, but if you know of a book especially applicable to this task I, shoot me the ISBN.
If you want to get some basic info on OpenGL programming, take a look at NeHe tutorials.
Assuming you're using Windows, get WinAPI documentation as well (Windows API documentation link at the bottom). Starting with 3D programming on Windows/Linux would make it easier (it's better documented, lots of examples, bigger communities). When you know what and how (very important!) you want to do - go back to homebrew creation. :)
Assuming you're using Windows, get WinAPI documentation as well (Windows API documentation link at the bottom). Starting with 3D programming on Windows/Linux would make it easier (it's better documented, lots of examples, bigger communities). When you know what and how (very important!) you want to do - go back to homebrew creation. :)
ok, some progress
So, I wrote a script in 3DS Max that gives me all the vert info off my own model. I kept the vert number the same to make the test simple. Copied the new vert info over the old in the sample file, compiled and popped onto the PSP and it works. So, my pipeline (even though rough) works. I can get a 12 face model from 3DS Max onto the PSP. So, now the question is, how do I make this general? Can I make an exteral file that has all my vert info on it and read in that data? What are the first steps to lead me to be able to do that?
Thanks!
Thanks!
My MaxScript spits out data from 3DS Max, then in Dev-C++ I overwrote the original data in the cube.c sample file with my own data. That was just for a test. Now, I want to make the program read in another file so I can eventually have a menu offering choices as to which model to view.
This is the sample cube code that I pasted my own data into:
In case you were wondering what Maxscript looks like, this is the code:
Max has z up, so I swapped y and z.
So, any links or ideas on how to do file I/O on psp?
This is the sample cube code that I pasted my own data into:
Code: Select all
/*
* PSP Software Development Kit - http://www.pspdev.org
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* Copyright (c) 2005 Jesper Svennevid
*/
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <pspgu.h>
#include <pspgum.h>
PSP_MODULE_INFO("Tri Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
#define printf pspDebugScreenPrintf
static unsigned int __attribute__((aligned(16))) list[262144];
extern unsigned char logo_start[];
struct Vertex
{
float u, v;
unsigned int color;
float x,y,z;
};
struct Vertex __attribute__((aligned(16))) vertices[12*3] =
{
{0.5,1.0, 0xff7f0000, 2.15068e-007, 0.035955, 0.0 }, //1
{0.0,0.0, 0xff7f0000, 0.634508, 1.30497, -0.634508 }, //2
{1.0,0.0, 0xff7f0000, -0.634508, 1.30497, -0.634508 }, //3
{0.5,1.0, 0xff7f0000, 2.15068e-007, 0.035955, 0.0 }, //1
{1.0,0.0, 0xff7f0000, -0.634508, 1.30497, -0.634508 }, //3
{0.0,0.0, 0xff7f0000, -0.634508, 1.30497, 0.634508 }, //4
{0.5,1.0, 0xff7f0000, 2.15068e-007, 0.035955, 0.0 }, //1
{0.0,0.0, 0xff7f0000, -0.634508, 1.30497, 0.634508 }, //4
{1.0,0.0, 0xff7f0000, 0.634508, 1.30497, 0.634508 }, //5
{0.5,1.0, 0xff7f0000, 2.15068e-007, 0.035955, 0.0 }, //1
{1.0,0.0, 0xff7f0000, 0.634508, 1.30497, 0.634508 }, //5
{0.0,0.0, 0xff7f0000, 0.634508, 1.30497, -0.634508 }, //2
{0.0,0.0, 0xff7f0000, 0.634508, 1.30497, -0.634508 }, //2
{0.0,1.0, 0xff7f0000, 0.0, 1.30497, 0.0 }, //6
{1.0,0.0, 0xff7f0000, -0.634508, 1.30497, -0.634508 }, //3
{1.0,0.0, 0xff7f0000, -0.634508, 1.30497, -0.634508 }, //3
{0.0,1.0, 0xff7f0000, 0.0, 1.30497, 0.0 }, //6
{0.0,0.0, 0xff7f0000, -0.634508, 1.30497, 0.634508 }, //4
{0.0,0.0, 0xff7f0000, -0.634508, 1.30497, 0.634508 }, //4
{0.0,1.0, 0xff7f0000, 0.0, 1.30497, 0.0 }, //6
{1.0,0.0, 0xff7f0000, 0.634508, 1.30497, 0.634508 }, //5
{1.0,0.0, 0xff7f0000, 0.634508, 1.30497, 0.634508 }, //5
{0.0,1.0, 0xff7f0000, 0.0, 1.30497, 0.0 }, //6
{0.0,0.0, 0xff7f0000, 0.634508, 1.30497, -0.634508 }, //2
{1.0,1.0, 0xff7f0000, 0.0, -0.035955, 0.0 }, //7
{1.0,0.0, 0xff7f0000, -0.634508, -1.30497, -0.634508 }, //8
{0.0,0.0, 0xff7f0000, 0.634508, -1.30497, -0.634508 }, //9
{1.0,1.0, 0xff7f0000, 0.0, -0.035955, 0.0 }, //7
{0.0,0.0, 0xff7f0000, 0.634508, -1.30497, -0.634508 }, //9
{0.5,0.5, 0xff7f0000, 0.634508, -1.30497, 0.634508 }, //10
{1.0,1.0, 0xff7f0000, 0.0, -0.035955, 0.0 }, //7
{0.5,0.5, 0xff7f0000, 0.634508, -1.30497, 0.634508 }, //10
{0.5,1.0, 0xff7f0000, -0.634508, -1.30497, 0.634508 }, //11
{1.0,1.0, 0xff7f0000, 0.0, -0.035955, 0.0 }, //7
{0.5,1.0, 0xff7f0000, -0.634508, -1.30497, 0.634508 }, //11
{1.0,0.0, 0xff7f0000, -0.634508, -1.30497, -0.634508 }, //8
{1.0,0.0, 0xff7f0000, -0.634508, -1.30497, -0.634508 }, //8
{0.5,1.0, 0xff7f0000, 0.0, -1.30497, 0.0 }, //12
{0.0,0.0, 0xff7f0000, 0.634508, -1.30497, -0.634508 }, //9
{0.0,0.0, 0xff7f0000, 0.634508, -1.30497, -0.634508 }, //9
{0.5,1.0, 0xff7f0000, 0.0, -1.30497, 0.0 }, //12
{0.5,0.5, 0xff7f0000, 0.634508, -1.30497, 0.634508 }, //10
{0.5,0.5, 0xff7f0000, 0.634508, -1.30497, 0.634508 }, //10
{0.5,1.0, 0xff7f0000, 0.0, -1.30497, 0.0 }, //12
{0.5,1.0, 0xff7f0000, -0.634508, -1.30497, 0.634508 }, //11
{0.5,1.0, 0xff7f0000, -0.634508, -1.30497, 0.634508 }, //11
{0.5,1.0, 0xff7f0000, 0.0, -1.30497, 0.0 }, //12
{1.0,0.0, 0xff7f0000, -0.634508, -1.30497, -0.634508 }, //8
};
int SetupCallbacks();
#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? */
int main(int argc, char* argv[])
{
SetupCallbacks();
// 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_CW);
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
int val = 0;
for(;;)
{
sceGuStart(GU_DIRECT,list);
// clear screen
sceGuClearColor(0xff554433);
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();
{
ScePspFVector3 pos = { 0, 0, -2.5f };
ScePspFVector3 rot = { val * 0.79f * (M_PI/180.0f), val * 0.98f * (M_PI/180.0f), val * 1.32f * (M_PI/180.0f) };
sceGumRotateXYZ(&rot);
sceGumTranslate(&pos);
}
// setup texture
sceGuTexMode(GU_PSM_4444,0,0,0);
sceGuTexImage(0,64,64,64,logo_start);
sceGuTexFunc(GU_TFX_ADD,GU_TCC_RGB);
sceGuTexEnvColor(0xffff00);
sceGuTexFilter(GU_LINEAR,GU_LINEAR);
sceGuTexScale(1.0f,1.0f);
sceGuTexOffset(0.0f,0.0f);
sceGuAmbientColor(0xffffffff);
// draw cube
sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,12*3,0,vertices);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
val++;
}
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;
}
Max has z up, so I swapped y and z.
Code: Select all
for a = 1 to (polyop.getNumFaces $) do
(
-- PSP Face Format
-- {u, v, color, x, y, z}
-- u, v: texture coordinates
-- color - color (0xAARRGGBB - alpha, red, green, blue)
-- x, y, z - position
vList = polyop.getFaceVerts $ a
for vFace = 1 to 3 do
(
vTemp = polyop.getVert $ vList[vFace]
UV = polyOp.getMapVert $ 1 vList[vFace]
format "{%,%, 0xff7f0000, %, %, % }, //%\n" UV.x UV.y (vTemp.x/100) (vTemp.z/100) (vTemp.y/100) (vList[vFace])
)
)
So, any links or ideas on how to do file I/O on psp?
not exactly
What I am trying to do is make a general viewer program that runs on the PSP, and anyone can then use my maxscript exporter to create a file. They would then copy the file to their psp and the model viewer would see that new file and load it up. So, I need to understand code that will see files in a psp folder, and then do a read file on the data.
I hope that makes sense...
I hope that makes sense...
Play with kernel/fileio sample application. You can use it to read your own file format (if needed). Modify MAX script so it saves it in easier to read format, e.g.:
N = number of polygons. Read one line from file (N value), allocate vertices table of N*3 size, load following rows and store data inside allocated table. Modify
to
and voila! Simple loader created. Probably you want to read about MAX model file format and read it directly from PSP instead of using MAX script (few of us have enough money for 3DSMAX for file conversion purposes only ;]).
Code: Select all
N
x,y,z,c,u,v
x,y,z,c,u,v
x,y,z,c,u,v
...
Code: Select all
sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,12*3,0,vertices);
Code: Select all
sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,N*3,0,vertices);
OK. I thought your problem was saving out the file from Max in the first place. PSP FileIO is documented here: http://psp.jim.sh/pspsdk-doc/group__FileIO.html
Searching on the forum brings some interesting discussions too.
Searching on the forum brings some interesting discussions too.
Thanks for the feedback
Thanks Kro and Ashley, I will take a look at your suggestions. I really appreciate it. Currently, I can paste in an arbitary numer of polys into the code and get it to display with uvs on the PSP, so this next step will get me even closer to final!
Why max?
Well, I create all my 3d models in Max. In fact, most games are developed with 3DS max (60% of all console games) so this will be useful to a lot of developers. The cool thing about this program is that any 3d package that supports scripting can spit out a file similar to what I am doing in Max. Anyway, the Max file format is not something you can read (closed format.)Probably you want to read about MAX model file format and read it directly from PSP instead of using MAX script (few of us have enough money for 3DSMAX for file conversion purposes only ;]).
Just some info...
while you're on it... simply convert on-thy-fly all textures into a PSP native format (power-of-two width, ABGR or BGR component ordering, 5650, 5551, 4444 or 8888 component depth). Then you can pass the loaded textures and vertex data directly to the GE without doing any expensive conversion on the PSP.
User ineraction added!
Okay, so I am stuck on the file i/o part. All the reference you guys supplied is great, but I need a stupid simple example to really undertand how it works. But, since I was stuck in that part, I want ahead and added button interaction. So, now you can rotate the model with the direction pad, and reset it with the x button.
So, my question is there a really simple example of file i/o ? I know it must be pretty easy, but I am having trouble wrapping my head around it...
Code: Select all
/*
* PSP Software Development Kit - http://www.pspdev.org
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* Copyright (c) 2005 Jesper Svennevid
*/
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <pspgu.h>
#include <pspgum.h>
#include <pspctrl.h>
PSP_MODULE_INFO("Tri Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
#define printf pspDebugScreenPrintf
static unsigned int __attribute__((aligned(16))) list[262144];
extern unsigned char logo_start[];
struct Vertex
{
float u, v;
unsigned int color;
float x,y,z;
};
struct Vertex __attribute__((aligned(16))) vertices[764*3] =
{
// Face: 1
{0.0853705,0.602419, 0xff7f0000, -0.773378, 0.243777, 0.391428 }, //45
{0.104532,0.611974, 0xff7f0000, -0.73747, 0.22865, 0.138037 }, //79
{0.126037,0.667144, 0xff7f0000, -0.697381, 0.333651, 0.147721 }, //24
// Face: 2
{0.126037,0.667144, 0xff7f0000, -0.697381, 0.333651, 0.147721 }, //24
{0.0944046,0.693024, 0xff7f0000, -0.756532, 0.414006, 0.390349 }, //23
{0.0853705,0.602419, 0xff7f0000, -0.773378, 0.243777, 0.391428 }, //45
--- LOTS OF FACES!!!! ---
// Face: 764
{0.643987,0.746828, 0xff7f0000, 0.268526, 0.454134, -0.0763672 }, //403
{0.646995,0.708613, 0xff7f0000, 0.274128, 0.383504, -0.0669522 }, //382
{0.710616,0.701221, 0xff7f0000, 0.392752, 0.36966, -0.0664474 }, //381
};
int SetupCallbacks();
#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? */
int main(int argc, char* argv[])
{
SetupCallbacks();
// 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_CW);
sceGuShadeModel(GU_SMOOTH);
sceGuEnable(GU_CULL_FACE);
sceGuEnable(GU_TEXTURE_2D);
sceGuEnable(GU_CLIP_PLANES);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuDisplay(GU_TRUE);
SceCtrlData pad;
// run sample
float xval = 0;
float yval = 0;
float zval = 0;
for(;;)
{
sceCtrlReadBufferPositive(&pad, 1);
if(pad.Buttons & PSP_CTRL_CROSS)
{
xval=0; yval=0; zval=0;
}
if(pad.Buttons & PSP_CTRL_DOWN)
{
xval = xval + .25;
}
if(pad.Buttons & PSP_CTRL_UP)
{
xval = xval - .25;
}
if(pad.Buttons & PSP_CTRL_LEFT)
{
yval = yval + .25;
}
if(pad.Buttons & PSP_CTRL_RIGHT)
{
yval = yval - .25;
}
sceGuStart(GU_DIRECT,list);
// clear screen
sceGuClearColor(0xff554433);
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();
{
ScePspFVector3 pos = { 0, 0, -2.5f };
ScePspFVector3 rot = {xval, yval, zval};
sceGumRotateXYZ(&rot);
sceGumTranslate(&pos);
}
// setup texture
sceGuTexMode(GU_PSM_4444,0,0,0);
sceGuTexImage(0,64,64,64,logo_start);
sceGuTexFunc(GU_TFX_ADD,GU_TCC_RGB);
sceGuTexEnvColor(0xffff00);
sceGuTexFilter(GU_LINEAR,GU_LINEAR);
sceGuTexScale(1.0f,1.0f);
sceGuTexOffset(0.0f,0.0f);
sceGuAmbientColor(0xffffffff);
// draw cube
sceGumDrawArray(GU_TRIANGLES,GU_TEXTURE_32BITF|GU_COLOR_8888|GU_VERTEX_32BITF|GU_TRANSFORM_3D,764*3,0,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;
}
first, add in your current code something like this:
EDIT: actually, you could just tweak your max exported script to write out to a similar file format.
which dumps your data to a file, then instead of having the static array:
which just reads it back to a dynamically allocaed array, all things being good, everything else should just work. Then you could prolly take the the creation code and run it on ur pc to create the data files. (on x86 you shouldnt have to worry about endianness)
Code: Select all
FILE *fp = fopen(filename,"w");
int numVerts = whatever;
fwrite(&numVerts,1,sizeof(int),fp);
fwrite(vertices, numVerts, sizeof(struct Vertex), fp);
fclose(fp);
which dumps your data to a file, then instead of having the static array:
Code: Select all
FILE *fp = fopen(filename,"r");
fread(&numVerts,1,sizeof(int),fp);
vertices = memalign(128,numverts * sizeof(struct vertex)); /* check syntax on this */
fread(vertices, numVerts, sizeof(struct Vertex), fp);
fclose(fp);
Damn, I need a decent signature!
thanks cheriff
Thanks for the feedback Cheriff.
I guess I need a little remedial programming help. Lets say to make things simple, I want to read from an asci file I wrote out of 3DSmax. Do I need to include any special .h files for file IO? I am getting a syntax error here:
I just want to open a test text file and I can't get it to compile now.
I see pspiofilemgr_kernel.h, and a lot of other files that might be needed, but non of them seem to help my problem when i include them.
Thanks for any help...
I guess I need a little remedial programming help. Lets say to make things simple, I want to read from an asci file I wrote out of 3DSmax. Do I need to include any special .h files for file IO? I am getting a syntax error here:
Code: Select all
FILE *file = fopen("test.txt", "r" );
I see pspiofilemgr_kernel.h, and a lot of other files that might be needed, but non of them seem to help my problem when i include them.
Thanks for any help...
okay that was right
So, that fixed one error, but now I am getting "initializer element is not constant" I googled the problem and got a lot of hits, but none made sense in a file io specific way. Any ideas?
you dont have that line outside a function (at topmost level) do you? If you need file to be global:
This are pretty standard generic c problems not limited to pspdev - perhaps you should brush up on the standary library a little? :)
Code: Select all
FILE *file;
int main(){
file = fpen("data.txt","r");
}
Damn, I need a decent signature!
yup
You nailed it. And yes, my c knowledge is lacking, I will admit. I am really a 3D artist who scripts and I am trying to branch out into coding. And, thanks to your help, I can now read in data from a text file! Yea! Next, I have to make a simple menu to allow users to pick a model from a list. Thanks again for the help.
i made this prog from the cube sample too, but i have some wrong triangles:
(two are wrong but it's not always the sames)
my msh format has no problem (checked with some tech) , nor texture loading and drawing.
here my code:
(two are wrong but it's not always the sames)
my msh format has no problem (checked with some tech) , nor texture loading and drawing.
here my code:
Code: Select all
#include <pspkernel.h>
#include <malloc.h>
#include <pspdisplay.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <pspgu.h>
#include <pspgum.h>
PSP_MODULE_INFO("3D Object Test", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER);
#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? */
struct Vertex
{
float tu, tv;
float nx,ny,nz;
float x,y,z;
};
static unsigned int __attribute__((aligned(16))) list[262144];
unsigned short __attribute__((aligned(16))) *indices;
unsigned char __attribute__((aligned(16))) *tex;
struct Vertex __attribute__((aligned(16))) *vertices;
int SetupCallbacks();
int main(int argc, char* argv[])
{
unsigned long nbvert; // vertices count
unsigned long nbface; // faces count
char ver[3]; //version (major, minor, release)
SetupCallbacks();
tex=(unsigned char*)malloc(256*256*4);
FILE *fd2 = fopen("ms0:/PSP/sword.raw", "rb");
fread((void*)tex, 256*256*4, 1, fd2);
fclose(fd2);
// load model
FILE *fd = fopen("ms0:/PSP/sword.msh","rb");
fseek(fd, 3, SEEK_CUR); // 'M', 'S', 'H'
fread((void*)ver, 3,1,fd); // major, minor, release
fread((void*)&nbvert, 4,1,fd); // vertices count
fread((void*)&nbface, 4,1,fd); // faces count
vertices=(struct Vertex*)memalign(16,sizeof(struct Vertex)*nbvert);
indices=(unsigned short*)memalign(16,sizeof(unsigned short)*nbface*3);
fread((void*)vertices, sizeof(struct Vertex),nbvert,fd);
fread((void*)indices, sizeof(unsigned short),nbface*3,fd);
fclose(fd);
// 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
ScePspFVector3 pos = { 50, 20, -50 };
ScePspFVector3 rot = { -1.6f,0,0 };
for(;;)
{
sceGuStart(GU_DIRECT,list);
// clear screen
sceGuClearColor(0xff000000);
sceGuClearDepth(0);
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);
// setup matrices
sceGumMatrixMode(GU_PROJECTION);
sceGumLoadIdentity();
sceGumPerspective(75.0f,16.0f/9.0f,0.5f,1000.0f);
sceGumMatrixMode(GU_VIEW);
sceGumLoadIdentity();
sceGumMatrixMode(GU_MODEL);
sceGumLoadIdentity();
sceGumRotateXYZ(&rot);
sceGumTranslate(&pos);
// setup texture
sceGuTexMode(GU_PSM_8888,0,0,0);
sceGuTexImage(0,256,256,256,tex);
sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB);
sceGuTexFilter(GU_LINEAR,GU_LINEAR);
// draw cube
sceGumDrawArray(GU_TRIANGLES,GU_INDEX_16BIT|GU_TEXTURE_32BITF|GU_NORMAL_32BITF|GU_VERTEX_32BITF|GU_TRANSFORM_3D,nbface*3,indices,vertices);
sceGuFinish();
sceGuSync(0,0);
sceDisplayWaitVblankStart();
sceGuSwapBuffers();
}
sceGuTerm();
sceKernelExitGame();
return 0;
}
... + callbacks
To flush the cache use this
Oh and the .3ds format is pretty open (although maybe not offically), i've been using .3ds files for my stuff as it's a relativly simple format to parse.
You can find a lot of the spec here, there maybe more detailed info elsewhere, but anything not documented here is probably little use anyway:
http://www.dcs.ed.ac.uk/home/mxr/gfx/3d/3DS.spec
Code: Select all
sceKernelDcacheWritebackAll();
You can find a lot of the spec here, there maybe more detailed info elsewhere, but anything not documented here is probably little use anyway:
http://www.dcs.ed.ac.uk/home/mxr/gfx/3d/3DS.spec
3ds
Yeah, the 3ds format is open, but I was referring to a .max file. 3DS is a pretty old format, and has limits on texture names at 8 chars. The exporter I am working on will be more robust that the 3ds format, but you need max to use it...
Also, someone mentioned earlier about using a png or other file format as texture for a model. Right now I just know how to use a raw file. are there any docs on how to load in another texture type?
Thanks again...
Oh, and one last question, bumpman, what psp screen cap software did you use?
Also, someone mentioned earlier about using a png or other file format as texture for a model. Right now I just know how to use a raw file. are there any docs on how to load in another texture type?
Thanks again...
Oh, and one last question, bumpman, what psp screen cap software did you use?
WAAAAAAAW it work =) thx thx thx to Holger and Ratty !!
i don't understand what is the cache but it work =)
neuro> webcam :D
about the other formats, i think we should search for docs about the format and translate the file to a raw... or use libs as pnglib ?
> about the 3ds format: i won't use this format, because i want put others info into my files ^^. and yes i think it is a bit old now.
i don't understand what is the cache but it work =)
neuro> webcam :D
about the other formats, i think we should search for docs about the format and translate the file to a raw... or use libs as pnglib ?
> about the 3ds format: i won't use this format, because i want put others info into my files ^^. and yes i think it is a bit old now.