April 25, 2024, 09:51:41 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Bare minimum 3D

Started by kryton9, September 13, 2006, 10:30:01 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

kryton9

September 13, 2006, 10:30:01 PM Last Edit: September 13, 2006, 10:51:44 PM by kryton9
To maybe get more involved with 3D, I decided to make the simplest 3d screen code I could.
As you can see it is not too scary and hopefully will get more of you playing with it.

To get into it, instead of the sphere try making a cylinder, rectangle. The methods are listed in 3d help:classes:c3dMesh

The other examples in the 3D section have code with more commands, for lighting, adding color to the object, and loading premade models from other programs.
Hope you all dabble with it a bit at least and have fun.

If you want to hide the cursor, just add this line to the program:
s.SetCursor(CS_CUSTOM,0);

global sub main()
{
C3DScreen s;
C3DCamera c;
C3DMesh m;
C3DObject scene;
C3DLight light;
s.CreateFullScreen(1024,768,32,true);
c.Create(s);
c.Position(0,0,-50);
m.CreateSphere(s,32,10,false);
m.Position(0,0,-12);
light.Create(s,LIGHT_POINT,1);
light.Position(0,100,-100);
scene.CreateScene(s);
scene.AddChild(light);
scene.AddChild(m);
do
{
s.Clear(RGBA(100,100,100,255));
s.BeginScene(c);
scene.Draw();
s.RenderText(10,10,"Esc to Quit",RGBA(200,200,200,255));
s.RenderScene();
}until GetKeyState(0x1B);// Escape Key to Quit
Scene.Free();
}

kryton9

September 13, 2006, 11:33:14 PM #1 Last Edit: September 13, 2006, 11:43:17 PM by kryton9
I thought I would take it a step further and here is a project version of it.
Unzip into one directory, Open up the project file:ÂÃ,  C3DEasy.awp

The files are:
C3DEasyMain.srcÂÃ,  ÂÃ,  This is the main source
C3DEasyClass.srcÂÃ,  ÂÃ,  This is the class
C3DEasy.incÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  This is the include, this should not be inserted into the project, but in the same folder as the project.

Here is the code for C3DEasyMain.src, in case you don't want to download to look at it. It does exactly what the program in the first post does, but in fewer lines in the main source.
You can use this then when you want to just do something in a hurry and get to coding a quick demo or something.

#include "C3DEasy.inc"
global sub main()
{
C3DEasy s;
do
{
s.Render();
}until GetKeyState(0x1B);// Escape Key to Quit
s.Exit();
}


Once I get my control system the way I like it, I will put it in here too, so you will have nice controls easilly too.

kryton9

September 13, 2006, 11:40:39 PM #2 Last Edit: September 13, 2006, 11:42:49 PM by kryton9
How could I pass parameters in the same line that I did:

C3DEasy s;

I would like to be able to pass parameters at the same time that I create the object s with C3DEasy.

Like screen resolution and depth, cursor on/off, default mesh or not, background color etc.
So it would look like something like this?

C3DEasy s(1024,768,32,false,3,color);

Or if no parameters it would just run the defaults.

kryton9

You might say, well what if I wanted to add my own objects using your C3DEasy, good question. Here is an example of adding a box to the scene.
This would be the new C3DEasyMain.src:

#include "C3DEasy.inc"
global sub main()
{
C3DEasy s;
C3DMesh m2;
m2.CreateBox(s.screen,2,2,2,false);
m2.Position(-12,0,-12);
s.s.AddChild(m2);
do
{
s.Render();
}until GetKeyState(0x1B);// Escape Key to Quit
s.Exit();
}

Ionic Wind Support Team

Constructor paramterers are not available yet.  They require the implementation of method overloading to work correctly.

For now you could just have an 'init' method.

Quote from: kryton9 on September 13, 2006, 11:40:39 PM
How could I pass parameters in the same line that I did:

C3DEasy s;

I would like to be able to pass parameters at the same time that I create the object s with C3DEasy.

Like screen resolution and depth, cursor on/off, default mesh or not, background color etc.
So it would look like something like this?

C3DEasy s(1024,768,32,false,3,color);

Or if no parameters it would just run the defaults.
Ionic Wind Support Team

kryton9

I will wait for your release when it is out. I am going to see if I can figure out how to autodetect the users graphics abilities and just autoset the resolution. That would be better anyways :)
Thanks for the quick reply however!!

kryton9

September 14, 2006, 01:34:05 AM #6 Last Edit: September 14, 2006, 01:36:14 AM by kryton9
Ok here is a version with basic user movement control thrown in.

W moves user forward
S moves user backwards
A moves user to the left
D moves user to the right

R resets to original view

The mouse controls where you look. So with almost one command you got a useable skeleton to have fun with 3d.

The x and y are where the mouse is on the screen, even though it is hidden.

The main source is just as it is listed in reply #3. In case you don't want to download to try it out.