April 24, 2024, 07:28:36 PM

News:

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


Fallen at the first hurdle...

Started by Kale, September 04, 2006, 11:49:56 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Kale

Ok, what am i doing wrong? I can't seem to get anything displayed using the 3D commands. Here's my code:


global sub main()
{
C3DScreen s;
C3DCamera c;
C3DMesh m;
C3DObject scene;
C3DLight light;
CDirectInput di;

s.CreateWindowed(0,0,640,480,AWS_CAPTION|AWS_VISIBLE|AWS_SIZE,0,"3D Test - ESC to exit",NULL,false);
di.Init(s);
s.CenterWindow();
c.Create(s);
c.Position(0,0,50);
c.LookAt(0, 0, 0);

m.LoadX(s,GetStartPath() + "invader_low.x");
m.Position(0,0,0);
m.EnableLighting(true);

light.Create(s,LIGHT_SPOT,1);
light.Position(0,20,0);
light.SetAttenuation(0,1/30.0,0);

scene.CreateScene(s);
scene.AddChild(light);
scene.AddChild(m);
do
{
s.Clear(RGBA(0,0,0,255));
s.BeginScene(c);
scene.Draw();
s.RenderScene();
}
until di.KeyDown(DIK_ESCAPE);
scene.Free();
}


Does anything jump out as being wrong?

J B Wood (Zumwalt)


declare import, timeGetTime(),int;
global sub main()
{
C3DScreen s;
C3DCamera c;
C3DMesh m;
C3DObject scene;
C3DLight light;
CDirectInput di;
float fTarget,fAdjust;
fTarget = 1.0f / /*FPS*/60.0f * 1000.0f;

s.CreateWindowed(0,0,640,480,AWS_CAPTION|AWS_VISIBLE|AWS_SIZE,0,"3D Test - ESC to exit",NULL,false);
di.Init(s);
s.CenterWindow();

c.Create(s);
c.Position(1,1,1);
c.Rotate(0,0,0);
c.Orient(0,0,1,0,100,0);
c.LookAt(0,0,0);


m.LoadX(s,GetStartPath() + "invader_low.x");
m.Scale(1,1,1);
m.Position(0,0,0);
m.Rotate(0,0,0);
m.EnableLighting(true);
m.UseVertexColor(true);

light.Create(s,LIGHT_SPOT,1);
light.Position(0,20,0);
light.SetAttenuation(0,1/30.0,0);

scene.CreateScene(s);
scene.AddChild(light);
scene.AddChild(m);

int starttime;
int fps=0;

do
{
starttime = timeGetTime();
s.Clear(RGBA(0,0,0,255));
s.BeginScene(c);
scene.Draw();
fps=s.RenderScene();
fAdjust=(timeGetTime()-startTime)/fTarget;
}until di.KeyDown(DIK_ESCAPE);
scene.Free();
}


If this doesn't work, there is a problem with the mesh.

kryton9

September 04, 2006, 12:23:53 PM #2 Last Edit: September 04, 2006, 12:35:10 PM by kryton9
You might want to try:
.LoadSkinnedXÂÃ,  instead of LoadX

Also this worked:

                light.Create(s,LIGHT_SPOT,1);
   light.Position(0,100,0);
   light.SetAttenuation(0,1/200.0,0);
   light.LookAt(0,0,0);

Ionic Wind Support Team

light.SetAttenuation(0,1/30.0,0);

Is a very large attenuation value.  Won't light up much.

Try: light.SetAttenuation(0,1/200.0,0);

Or better yet turn lighting off for the mesh until you get everything else working.

Ionic Wind Support Team

J B Wood (Zumwalt)


kryton9

September 04, 2006, 12:36:22 PM #5 Last Edit: September 04, 2006, 12:38:01 PM by kryton9
I edited my earlier Post and got it working. It is a spot light so it has to look a the object.
I also set the attenuation and I got it to see a mesh I put in.

The LookAt command saves the day again :)

Kale

Yep, got it. It was the attenuation setting. Ta guys!

BTW what the heck is attenuation anyway? ;)

Todd Riggins

Hi Kale,

Attentuation is how the light level decreases over distance.
Brought to you buy: http://www.exodev.com

Kale

Okay, i've been playing with different settings all night trying to get a handle on the 3D stuff. It's going well! There is however a little issue. In this following snippet the model displays fine and dandy and rotates nicely in the camera. But, when i un-comment the '//D3DMATERIAL SphereMaterial;' line, everything dissapears. Why is this?


global sub main()
{
C3DScreen Screen;
C3DCamera Camera;
C3DMesh Mesh;

//D3DMATERIAL SphereMaterial;

C3DObject Scene;
C3DLight Light;
CDirectInput DirectInput;
float Rotation;

Screen.CreateWindowed(0, 0, 800, 600, AWS_CENTERED | AWS_CAPTION | AWS_VISIBLE | AWS_SIZE, 0, "3D Test", NULL, false);
DirectInput.Init(Screen);

Camera.Create(Screen);
Camera.Position(0, 1, 2.5);
Camera.LookAt(0, 0.25, 0);
Camera.SetFrontPlane(1);
Camera.SetBackPlane(50);

Mesh.LoadX(Screen,GetStartPath() + "invader_low.x");
Mesh.EnableLighting(true);

Light.Create(Screen,LIGHT_SPOT, 1);
Light.Position(0, 50, 50);
Light.SetDirection(0, 0, 0);

Scene.CreateScene(Screen);
Scene.AddChild(Light);
Scene.AddChild(Mesh);

while (!DirectInput.KeyDown(DIK_ESCAPE))
{
Screen.Clear(RGBA(32, 23, 30, 255));
Screen.BeginScene(Camera);
Scene.Draw();
Screen.RenderScene();
Rotation += 0.00035f;
Mesh.Rotate(0, Rotation, 0);
}
Scene.Free();
}


See attached for mesh.

Ionic Wind Support Team

Variables are not initialzied unless you specifically set them, unless the variable is a global one in which case it is set to 0 by the linker.

Just a guess of course since I'm in linux at the moment but try:

float Rotation = 0f;

Ionic Wind Support Team

Kale

Quote from: Paul Turley on September 04, 2006, 06:12:50 PM
Variables are not initialzied unless you specifically set them, unless the variable is a global one in which case it is set to 0 by the linker.

Just a guess of course since I'm in linux at the moment but try:

float Rotation = 0f;

Yes, that cures it. But without this initialisation what goes wrong? Because it was the '//D3DMATERIAL SphereMaterial;' that seemed to cause the problem.

Ionic Wind Support Team

Variables in a subroutine are located on the programs stack.  The stack can contain leftovers from previous function calls so if you don't initialize a variable it will contain random contents.   Adding the D3DMATERIAL structure moved the float variable to a different location on the stack.

So the location is was previously at was probably a zero, but the new location had some non floating point value.

It's the first thing I look for when programming in C ;)  Which is how I was able to readily spot it.
Ionic Wind Support Team

Kale

Quote from: Paul Turley on September 05, 2006, 05:57:41 PM
Variables in a subroutine are located on the programs stack.ÂÃ,  The stack can contain leftovers from previous function calls so if you don't initialize a variable it will contain random contents.ÂÃ,  ÂÃ, Adding the D3DMATERIAL structure moved the float variable to a different location on the stack.

So the location is was previously at was probably a zero, but the new location had some non floating point value.

It's the first thing I look for when programming in C ;)ÂÃ,  Which is how I was able to readily spot it.

Very useful to know, thankyou.