You are not logged in.

#1 2010-11-22 22:47:15

owen
Member

3d programming questions

This is my second attempt at using grrlib and devkitpro and I happy to say that I finally got the basics up and running.  I am always glad to see projects that work as expected without lots of hurdles to cross.

Now for the questions;

1 - GRRLIB_PtInRect, GRRLIB_RectInRect, and  GRRLIB_RectOnRect seem to be used for 2d collision detection.  Are there functions currently available for 3d collision detection?

2 - Presently I am coding in C, using the cube example 5.  The example draws directly to the screen.  Is there some kind of internal object structure/array/buffer in GRRLIB that I should be using? or is drawing directly to the screen the way it is done in wii development?

Offline

 

#2 2010-11-23 00:11:13

Crayon
Bad Mother Fucker

Re: 3d programming questions

1- No, but you could use the physics library called Bullet: http://wiibrew.org/wiki/List_of_develop … _Libraries
2- It's OK to draw directly to the screen.

Offline

 

#3 2010-11-23 01:13:10

owen
Member

Re: 3d programming questions

@crayon thank you very much for the info.  Bullet seems a bit too advanced for me, plus its in C++.  I will have to try and work around the collision thing.  OK,  cool.  I will do some drawing experiments to see how it works out. thanx.

Offline

 

#4 2010-11-23 04:36:37

Crayon
Bad Mother Fucker

Re: 3d programming questions

BTW, you don't draw directly on screen, you draw to a frame buffer called xfb. Which is in fact a two frame buffer used for double buffering. Here is the code from GRRLIB_core.c:

Code:

    // Get some memory to use for a "double buffered" frame buffer
    if ( !(xfb[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode))) )  return -1;
    if ( !(xfb[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode))) )  return -1;

In the GRRLIB_Render function (GRRLIB_render.c) the buffer switches and the next frame buffer is set:

Code:

    fb ^= 1;  // Toggle framebuffer index

    // some code goes HERE

    VIDEO_SetNextFramebuffer(xfb[fb]);  // Select eXternal Frame Buffer
    VIDEO_Flush();                      // Flush video buffer to screen

Offline

 

#5 2010-11-23 17:47:47

owen
Member

Re: 3d programming questions

ok, but in my previous adventures with drawing in 3d engines I always had to put objects on a "stack" and then the engine would draw everything that was added.  I'm not sure if it is related to the GPU or just the nature of the engine.  I did a few tests yesterday and it seems to work fine so far. 

I just need to read the documentation a little more to understand how to draw shapes with the inline functions.  I've been hacking at drawing a square with the draw functions but testing is tricky with my current SD card swaping setup.  I'm looking into using google sketch up then exporting the model as a COLLADA file.   Are they any quick/simple ways to draw up simple shapes and place them into my code? 

NB.  I'm working on a function such as draw_square(x,y,z, hieght, width, col) right now, pretty basic stuff I know but I'm a 2d guy, so its pure trial and error. lol

Offline

 

#6 2010-11-23 19:38:50

Crayon
Bad Mother Fucker

Re: 3d programming questions

owen wrote:

NB.  I'm working on a function such as draw_square(x,y,z, hieght, width, col) right now, pretty basic stuff I know but I'm a 2d guy, so its pure trial and error. lol

You know you could use GRRLIB_Rectangle: http://grrlib.santo.fr/doc/group___all_ … 96a3feec4d

Offline

 

#7 2010-11-25 08:27:27

owen
Member

Re: 3d programming questions

So I have been make some progress with this project and now I have another technical question (not sure how much I can ask or  if I should start a new thread or just keep posting in this one) but anyway here goes;

Simple question:  What are the other constants that I can use with this function GX_Begin(GX_QUADS, GX_VTXFMT0, 144 )? 

Found them: GX_TRIANGLES,GX_POINTS,GX_LINES,GX_TRIANGLESTRIP,GX_TRIANGLEFAN,GX_QUADS

Complicated Background: the function works but I think the data that I am drawing is not formated as QUADS but something else.  When the code is run the basic shape is formed but the last point is misplaced or attached to the base.  I think I need to do something special on the fourth point or I'm using the wrong GX constant for the data.  I tried all the constants they all create similar results as in the video except gx_points which shows all the dots at the right places but has no fill.

The code below seems to work as it should (I am just posting it for reference).  I am getting the points from a sketchup DAE file which has alot of information that I think I'm missing something from.

I've uploaded a video of what the out put.  Each side of the shape is a flat square.  It seems like my draw function (or the order of the data) is placing the 4th point at the wrong place resulting in holes in the shape.

Code:

    int i=0, step=0, col_step=0;
    float coords[3]={-1.0f,1.0f,-1.0f};
    float points[144] = {86.28997730703179,94.45135246135655,0,1.414977307031791,16.57635246135655,0
    ,1.414977307031791,94.45135246135655,0,86.28997730703179,16.57635246135655,0,86.28997730703179,
    16.57635246135655,19.375,1.414977307031791,16.57635246135655,0,86.28997730703179,16.57635246135655,
    0,1.414977307031791,16.57635246135655,19.375,1.414977307031791,94.45135246135655,19.375,
    1.414977307031791,16.57635246135655,0,1.414977307031791,16.57635246135655,19.375,1.414977307031791,
    94.45135246135655,0,26.24824869361981,94.45135246135655,51.125,51.18574869361981,94.45135246135655,
    19.375,26.24824869361981,94.45135246135655,19.375,51.18574869361981,94.45135246135655,51.125,
    1.414977307031791,94.45135246135655,19.375,86.28997730703179,94.45135246135655,0,1.414977307031791,
    94.45135246135655,0,86.28997730703179,94.45135246135655,19.375,86.28997730703179,94.45135246135655,0
    ,86.28997730703179,16.57635246135655,19.375,86.28997730703179,16.57635246135655,0,86.28997730703179,
    94.45135246135655,19.375,1.414977307031791,16.57635246135655,19.375,26.24824869361981,
    54.10162986690605,19.375,1.414977307031791,94.45135246135655,19.375,86.28997730703179,16.57635246135655,
    19.375,51.18574869361981,54.10162986690605,19.375,51.18574869361981,94.45135246135655,19.375,86.28997730703179,
    94.45135246135655,19.375,26.24824869361981,94.45135246135655,19.375,26.24824869361981,94.45135246135655,
    51.125,26.24824869361981,54.10162986690605,19.375,26.24824869361981,54.10162986690605,51.125,
    26.24824869361981,94.45135246135655,19.375,51.18574869361981,54.10162986690605,51.125,26.24824869361981,
    94.45135246135655,51.125,26.24824869361981,54.10162986690605,51.125,51.18574869361981,94.45135246135655,
    51.125,51.18574869361981,94.45135246135655,19.375,51.18574869361981,54.10162986690605,51.125,51.18574869361981,
    54.10162986690605,19.375,51.18574869361981,94.45135246135655,51.125,51.18574869361981,54.10162986690605,51.125,
    26.24824869361981,54.10162986690605,19.375,51.18574869361981,54.10162986690605,19.375,26.24824869361981,
    54.10162986690605,51.125};


    GRRLIB_ObjectView( x, y,cubeZ, a,a*2,a*3,1,1,1);
        GX_Begin(GX_QUADS, GX_VTXFMT0, 144/3 );
        
        for(i=0; i<t; i++) {
            coords[step]=points[i];
            step++;
            if(step > 2) {
                step=0;
                GX_Position3f32(coords[0],coords[1],coords[2]);
                GX_Color1u32(col[col_step]);
                col_step++;
                if(col_step > 2) col_step=0;
                
            }
        }
    
        GX_End();

sorry for the long winded post, i even had video too, lol.

Last edited by owen (2010-11-25 17:03:41)

Offline

 

#8 2010-11-25 18:34:25

NoNameNo
Administrator

Re: 3d programming questions

i think, as you do not know the "format or order" of the exported stuff, you should start exporting a simple triangle, then a simple square, then a simple cube, like this its easiest to understand what is exported and how wink

REgards,
NNN

Offline

 

#9 2010-11-25 18:48:04

owen
Member

Re: 3d programming questions

@NNN Yes that will be the next thing I will attempt.  The formate seems to be x,y,z,x,y,z,x,y,z or possibly some kinda 4th dimension. lol. but will run some more tests.

Offline

 

#10 2010-11-26 04:13:08

owen
Member

Re: 3d programming questions

I looked into it and after getting pen and paper and drawing out the points I realised that the points where is a strange order that made the fill overlap when it tries to close the shape.  The points draw perfectly but the overlap causes the GX_QUADS to messup.  I realise that I wasn't getting anywhere with it so I gave up.  I will have to find another way to draw simple 3d shapes and generate the points for the code.

Last edited by owen (2010-11-26 05:10:57)

Offline

 

#11 2010-11-26 05:05:25

NoNameNo
Administrator

Re: 3d programming questions

personally i use cinema4d to modeling, then triangulate my object, then i use a plugin called addnormal, and another plugin called riptide to export it as .obj.
after that i coded a little php that convert this obj to an array. I bet there is easier way to get simple model wink

Offline

 

#12 2010-11-28 22:42:03

mdbrim
Member

Re: 3d programming questions

nonameno... you gonna send me those scripts and my model? big_smile

I've been using simple planes to edit my boundaries, but looking forward to using cinema4d to model more stuff!

Thanks man.

Offline

 

#13 2010-11-29 01:52:40

owen
Member

Re: 3d programming questions

Oh and I solved the problem with the Collada file from Sketchup.  How the Collada file works is that each node has different information for the shape. the first node gives you the points, the second gives the normals (which is of no use to me now ) and the third gives the order of the verticies and the draw pattern (TRIANGLES,POINTS,LINES,etc).  The count of vertices may also need be multipled by 3.  The numbers given in the verticies are array positions.

the final code came out like this;

Code:

float points[600] = {
        13.67999999999997,0,1.579999999999999,0,27.36,-0.02000000000000046,6.839999999999993,
0,1.579999999999999,0,27.36,-1.620000000000002,13.67999999999997,0,1.579999999999999,13.67999999999997,0,
-1.620000000000002,0,27.36,-0.02000000000000046,6.839999999999993,0,1.579999999999999,0,27.36,
-0.02000000000000046,3.419999999999987,0,1.579999999999999,13.67999999999997,0,-1.620000000000002,3.419999999999987,
0,1.579999999999999,0,
0,-4.820000000000002,13.67999999999997,0,1.579999999999999,6.839999999999993,0,1.579999999999999,0,13.68,
1.579999999999999,0,0,-4.820000000000002,0,0,4.820000000000004,0,13.68,-4.820000000000002,0,
27.36,-0.02000000000000046,0,27.36,-1.620000000000002,0,27.36,-0.02000000000000046,-13.67999999999999,

0,-1.620000000000002,-13.67999999999999,0,1.579999999999999,0,27.36,
-1.620000000000002,0,27.36,-1.620000000000002,13.67999999999997,0,-1.620000000000002,6.839999999999993,13.68,-3.22,3.419999999999987,
0,1.579999999999999,0,27.36,-0.02000000000000046,0,13.68,1.579999999999999,0,0,4.820000000000004,
6.839999999999993,
13.68,-3.22,0,0,-4.820000000000002,0,13.68,-4.820000000000002,13.67999999999997,0,
-1.620000000000002,0,27.36,-0.02000000000000046,-3.420000000000004,0,1.579999999999999,0,13.68,
1.579999999999999,0,13.68,-4.820000000000002,-6.840000000000001,13.68,-3.22,0,27.36,
-1.620000000000002,6.839999999999993,13.68,-3.22,0,13.68,-4.820000000000002,0,27.36,
-1.620000000000002,-6.840000000000001,13.68,-3.22,0,0,
-4.820000000000002,-13.67999999999999,0,-1.620000000000002,0,13.68,-4.820000000000002,-3.420000000000004,0,1.579999999999999,
0,0,4.820000000000004,0,0,4.820000000000004,
-13.67999999999999,0,-1.620000000000002,-13.67999999999999,0,1.579999999999999,
-6.840000000000001,0,1.579999999999999,0,27.36,-0.02000000000000046,-13.67999999999999,
0,1.579999999999999,-6.840000000000001,0,1.579999999999999,0,27.36,-1.620000000000002,
-6.840000000000001,13.68,-3.22,-13.67999999999999,0,-1.620000000000002,6.839999999999993,
13.68,-3.22,0,27.36,-1.620000000000002,-6.840000000000001,13.68,-3.22,-6.840000000000001,13.68,
-3.22,0,13.68,-4.820000000000002,6.839999999999993,13.68,-3.22,-3.420000000000004,0,1.579999999999999
    };
    int triangles[600] = {
        0,1,2,3,4,5,4,3,6,7,8,9,10,11,12,11,10,13,11,13,14,15,16,17,16,15,18,18,15,19,
18,19,20,21,22,23,22,21,24,25,26,27,28,29,30,31,12,11,32,33,34,33,32,35,36,37,38,39,40,
41,42,43,44,45,46,47,46,45,48,31,49,12,38,37,50,28,30,51,49,52,12,52,49,53,53,49,54,55,56,
57,58,59,60,61,62,63,64,65,66,55,57,67
    };

    int total_points=204, max_triangles=34, point=0;

    GRRLIB_ObjectView( x, y,cubeZ, ax,ay,az,1,1,1);
    
        GX_Begin( GX_TRIANGLES, GX_VTXFMT0, max_triangles*3 );
        
        for(i=0; i<max_triangles*3; i++) {
            point=max_step * triangles[i];
            
            GX_Position3f32( points[point], points[point+1], points[point+2] );
                
        }
    
        GX_End();

Last edited by owen (2010-11-29 01:55:48)

Offline

 

#14 2010-12-14 17:35:20

owen
Member

Re: 3d programming questions

So I am drawing my shape correctly but I have these points called "normals".  What are good for?  do I have to plot them?  am I going to need them further down the road?

give a simple explanation please cause I read the wikipedia page and i could not make heads or tails of why i need them.

Offline

 

#15 2010-12-15 08:22:10

NoNameNo
Administrator

Re: 3d programming questions

normal are used to process light reflexion on faces.
when you use the GRRLIB_3dMode function , the latest param is a bool, saying if you will send normal or not.

exemple
GRRLIB_3dMode(0.1, 1000, 45, 0, 1);

then if you say that you will send normal you will HAVE to for each point (in this specific order position, normal, color).

exemple :
            GX_Position3f32(10, 10, 10);
            GX_Normal3f32(0, 0, 1);
            GX_Color1u32(0xFFFFFFFF);

hope it will help.

ps: if you do not use light, using normal is useless.
ps2: normal value have to be normalized (in the range of -1 and 1)

Offline

 

#16 2010-12-15 17:28:26

owen
Member

Re: 3d programming questions

Ooh now I see why GRRLIB_DrawCylinder(), GRRLIB_DrawCube() crashes when I try to use them, it's because they assume that I have send-normals set to true which I have set to false in my program.  There should be a note on those functions saying that they require that to be set.

I have no need for lights at present so I guess I can skip normals.  thanx.

Offline

 

#17 2010-12-27 18:28:16

owen
Member

Re: 3d programming questions

Hello again I hope you guy had a happy christmas or xmas.

I finally made a Wiibrew page for my game.

My question now is whats the easiest way to make a skybox for it? 

Presently I am using a very large 3d cube.  I representing the ground that extends all the way into the distance and very wide so that player cannot see the edges.  I imagine that drawing such a big cube would affect my frame rate but it has not happened yet.  is there another way?

Offline

 

Board footer

Powered by FluxBB