May 02, 2024, 12:23:38 AM

News:

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


Where can i find a reference for the 3D classes?

Started by Kale, July 25, 2006, 01:37:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Kale

Where can i find a reference for the 3D classes? I just need a boot in the right direction to know what methods are available. ;D

Parker

Aurora directory\bin\... (hehe, I need to update. I don't have the 3D include)

but it's in there, probably called something like dx3d.inc.


Ionic Wind Support Team

Help menu.  Aurora 3D help contains a skeleton guide.
Ionic Wind Support Team

Kale

Quote from: Paul Turley on July 25, 2006, 03:58:19 PM
Help menu.  Aurora 3D help contains a skeleton guide.

Great Ta!

Just one question:

C3DObject::GetPosition(int bWorld),VECTOR3;

What does 'bWorld' refer to?

Ionic Wind Support Team

Objects have local and world coordinates.  For instance if you have a moon as a child of a planet mesh and that moon is set to rotate around the planet using a transform object then the position of the moon can be expressed as either it's local XYZ position or transformed to world coordiantes.

Ionic Wind Support Team

Kale

Quote from: Paul Turley on July 25, 2006, 11:01:30 PM
Objects have local and world coordinates.  For instance if you have a moon as a child of a planet mesh and that moon is set to rotate around the planet using a transform object then the position of the moon can be expressed as either it's local XYZ position or transformed to world coordiantes.

Thanks for your explanation but i don't suppose you have time for a wee example? ;D transform object? transformed to world coordiantes?

I'm a little new to 3D programming but not OOP, so i'm getting most of it. :)

Ionic Wind Support Team

July 26, 2006, 12:40:38 PM #7 Last Edit: July 26, 2006, 12:53:10 PM by Paul Turley
OK here is an example that shows a childs coordinates are either relative to it's parent (local) or relative to the world.  As with most of my examples I add a little more so you'll learn something new.


import int timeGetTime();
#define DegToRad 0.01745329251995
//Arrow keys to move camera.
//PgUp/PgDn to pan up and down.
//Z and X to rotate on Z axis.

import int QueryPerformanceFrequency(int64 *lpFrequency);
import int QueryPerformanceCounter(int64 *lpPerformanceCount);


global sub main()
{
C3DScreen s;
C3DCamera c;
C3DMesh planet,moon;
C3DObject scene,trans;
C3DLight light;
CDirectInput di;
double fTarget=75.0,fAdjust = 1.0;
int64 freq;
QueryPerformanceFrequency(freq);
double dfreq = freq;

//s.CreateFullScreen(800,600,32,true);
s.CreateWindowed(0,0,800,600,AWS_CAPTION|AWS_VISIBLE|AWS_SIZE|AWS_CENTERED,0,"3D Test - ESC exits",NULL,true);

di.Init(s);
c.Create(s);
c.Position(0,0,-8);
c.Orient(0,0,1,0,1,0);
c.SetBackPlane(500);

s.Clear(RGBA(0,0,0,255));
s.BeginScene(c);
s.RenderText(0,10,"Loading objects...",RGBA(255,255,0,255));
s.RenderScene();


//create the scene and the objects
light.Create(s,LIGHT_POINT,1);
light.Position(0,20,-150);
light.SetAttenuation(0,1/200.0,0);
light.SetSpecular(.5,.5,.5,1);
light.SetAmbient(.4,.4,.4,1);

scene.CreateScene(s);
planet.CreateSphere(s,25,1,false);
moon.createSphere(s,15,.3,false);
trans.CreateTransform(s);

scene.AddChild(planet);
scene.AddChild(light);
planet.AddChild(trans);
trans.AddChild(moon);
moon.Position(3,0,0);
planet.LoadTexture(0,GetStartPath() + "media\\tile3.tga",0);

//'color' the moon
D3DMATERIAL mat;
mat.Diffuse = RGBAtoD3DC(RGBA(255,0,0,255));
mat.Specular = RGBAtoD3DC(RGBA(255,255,0,255));
mat.Ambient = RGBAtoD3DC(RGBA(0,0,0,0));
mat.Emissive = RGBAtoD3DC(RGBA(0,0,0,0));
mat.Power = 0.0;
moon.SetMaterial(mat);
moon.UseVertexColor(false);

double startTime = 0.0;
int64 iStartTime;

do
{
QueryPerformanceCounter(iStartTime);
startTime = iStartTime;

IF di.KeyDown(DIK_UP)
c.Move(0.0f,.25 * fAdjust);
IF di.KeyDown(DIK_DOWN)
c.Move(0.0f,-.25* fAdjust);
IF di.KeyDown(DIK_RIGHT)
c.Rotate(1.0*DegToRad*fAdjust,0,0);
IF di.KeyDown(DIK_LEFT)
c.Rotate(-1.0*DegToRad*fAdjust,0,0);
IF di.KeyDown(DIK_Z)
c.Rotate(0,0,-1.0*DegToRad*fAdjust);
IF di.KeyDown(DIK_X)
c.Rotate(0,0,1.0*DegToRad*fAdjust);
IF di.KeyDown(DIK_PRIOR)
c.Rotate(0,-1.0*DegToRad*fAdjust,0);
IF di.KeyDown(DIK_NEXT)
c.Rotate(0,1.0*DegToRad*fAdjust,0);
IF di.KeyDown(DIK_R)
c.LookAt(0,0,0);
trans.Rotate(0,timeGetTime()/1000.0,0);

VECTOR3 vLocal = moon.GetPosition(false);
VECTOR3 vWorld = moon.GetPosition(true);
localtext = USING("& X:%f###.## Y:%f###.## Z:%f###.##","Local Coordinates ",vLocal.x,vLocal.y,vLocal.z);
worldtext = USING("& X:%f###.## Y:%f###.## Z:%f###.##","World Coordinates ",vWorld.x,vWorld.y,vWorld.z);

s.Clear(RGBA(0,0,0,255));
s.BeginScene(c);
scene.Draw();
s.RenderText(0,10,localtext,RGBA(255,255,255,255));
s.RenderText(0,30,worldtext,RGBA(255,255,255,255));
s.RenderScene();
QueryPerformanceCounter(iStartTime);
fAdjust = ((iStartTime - startTime) / dfreq) * fTarget;

}until di.KeyDown(DIK_ESCAPE);
scene.Free();

}

SUB RGBAtoD3DC(UINT col),D3DCOLORVALUE
{
D3DCOLORVALUE ret;
ret.b = (col & 0xff) / 255.0;
ret.g = ((col & 0xff00) >> 8) / 255.0;
ret.r = ((col & 0xff0000) >> 16) / 255.0;
ret.a = ((col & 0xff000000) >> 24) / 255.0;
return ret;
}
Ionic Wind Support Team

kryton9

That is really nice Paul. Now that I am about 70% done with the c++ quick reference, once I finish that part. Then I will do the same for the Aurora side and hopefully by then. I will really be able to appreciate the cool things you are doing, not just as I am now by running the example, but by seeing the magic in the code.

kryton9

July 26, 2006, 02:55:03 PM #9 Last Edit: July 26, 2006, 03:11:26 PM by kryton9
Ok, this is just too much fun. Been looking at the code and playing. Am in love with Aurora now and can't wait to really grasp it.
This is just a mod to Paul's great example and you can see by tinkering around with the code and then figuring out the relationships, can do some really cool things.
import int timeGetTime();
#define DegToRad 0.01745329251995
//Arrow keys to move camera.
//PgUp/PgDn to pan up and down.
//Z and X to rotate on Z axis.

import int QueryPerformanceFrequency(int64 *lpFrequency);
import int QueryPerformanceCounter(int64 *lpPerformanceCount);


global sub main()
{
C3DScreen s;
C3DCamera c;
C3DMesh sun,planet,moon;
C3DObject scene,trans, trans2;
C3DLight light;
CDirectInput di;
double fTarget=75.0,fAdjust = 1.0;
int64 freq;
QueryPerformanceFrequency(freq);
double dfreq = freq;

//s.CreateFullScreen(800,600,32,true);
s.CreateWindowed(0,0,800,600,AWS_CAPTION|AWS_VISIBLE|AWS_SIZE|AWS_CENTERED,0,"3D Test - ESC exits",NULL,true);

di.Init(s);
c.Create(s);
c.Position(0,0,-8);
c.Orient(0,0,1,0,1,0);
c.SetBackPlane(500);

s.Clear(RGBA(0,0,0,255));
s.BeginScene(c);
s.RenderText(0,10,"Loading objects...",RGBA(255,255,0,255));
s.RenderScene();


//create the scene and the objects
light.Create(s,LIGHT_POINT,1);
light.Position(0,20,-150);
light.SetAttenuation(0,1/200.0,0);
light.SetSpecular(.5,.5,.5,1);
light.SetAmbient(.4,.4,.4,1);

scene.CreateScene(s);
sun.CreateSphere(s,25,1,false);
planet.createSphere(s,15,.3,false);
moon.createSphere(s,10,.1,false);
trans.CreateTransform(s);
trans2.CreateTransform(s);

scene.AddChild(sun);
scene.AddChild(light);
scene.AddChild(trans);
trans.AddChild(planet);
planet.Position(3,0,0);
planet.AddChild(trans2);
trans2.AddChild(moon);
moon.Position(0.5,0,0);


//'color' the planet
D3DMATERIAL mat;
mat.Diffuse = RGBAtoD3DC(RGBA(150,150,255,255));
mat.Specular = RGBAtoD3DC(RGBA(255,255,0,255));
mat.Ambient = RGBAtoD3DC(RGBA(0,0,0,0));
mat.Emissive = RGBAtoD3DC(RGBA(0,0,0,0));
mat.Power = 0.0;
planet.SetMaterial(mat);
planet.UseVertexColor(false);
//'color' the sun
D3DMATERIAL mat2;
mat2.Diffuse = RGBAtoD3DC(RGBA(255,150,0,255));
mat2.Specular = RGBAtoD3DC(RGBA(255,255,0,255));
mat2.Ambient = RGBAtoD3DC(RGBA(0,0,0,0));
mat2.Emissive = RGBAtoD3DC(RGBA(0,0,0,0));
mat2.Power = 0.0;
sun.SetMaterial(mat2);
sun.UseVertexColor(false);

double startTime = 0.0;
int64 iStartTime;

do
{
QueryPerformanceCounter(iStartTime);
startTime = iStartTime;

IF di.KeyDown(DIK_UP)
c.Move(0.0f,.25 * fAdjust);
IF di.KeyDown(DIK_DOWN)
c.Move(0.0f,-.25* fAdjust);
IF di.KeyDown(DIK_RIGHT)
c.Rotate(1.0*DegToRad*fAdjust,0,0);
IF di.KeyDown(DIK_LEFT)
c.Rotate(-1.0*DegToRad*fAdjust,0,0);
IF di.KeyDown(DIK_Z)
c.Rotate(0,0,-1.0*DegToRad*fAdjust);
IF di.KeyDown(DIK_X)
c.Rotate(0,0,1.0*DegToRad*fAdjust);
IF di.KeyDown(DIK_PRIOR)
c.Rotate(0,-1.0*DegToRad*fAdjust,0);
IF di.KeyDown(DIK_NEXT)
c.Rotate(0,1.0*DegToRad*fAdjust,0);
IF di.KeyDown(DIK_R)
c.LookAt(0,0,0);
trans.Rotate(0,timeGetTime()/1000.0,0);
trans2.Rotate(-10,timeGetTime()/500.0,0);

VECTOR3 vWorld2 = moon.GetPosition(true);
worldtext2 = USING("& X:%f###.## Y:%f###.## Z:%f###.##"," Moon World Coordinates ",vWorld2.x,vWorld2.y,vWorld2.z);
VECTOR3 vLocal = planet.GetPosition(false);
VECTOR3 vWorld = planet.GetPosition(true);
localtext = USING("& X:%f###.## Y:%f###.## Z:%f###.##","Planet Local Coordinates ",vLocal.x,vLocal.y,vLocal.z);
worldtext = USING("& X:%f###.## Y:%f###.## Z:%f###.##","Planet World Coordinates ",vWorld.x,vWorld.y,vWorld.z);

s.Clear(RGBA(0,0,0,255));
s.BeginScene(c);
scene.Draw();
s.RenderText(0,10,localtext,RGBA(100,100,255,255));
s.RenderText(0,30,worldtext,RGBA(100,100,255,255));
s.RenderText(0,50,worldtext2,RGBA(200,200,200,255));
s.RenderScene();
QueryPerformanceCounter(iStartTime);
fAdjust = ((iStartTime - startTime) / dfreq) * fTarget;

}until di.KeyDown(DIK_ESCAPE);
scene.Free();

}

SUB RGBAtoD3DC(UINT col),D3DCOLORVALUE
{
D3DCOLORVALUE ret;
ret.b = (col & 0xff) / 255.0;
ret.g = ((col & 0xff00) >> 8) / 255.0;
ret.r = ((col & 0xff0000) >> 16) / 255.0;
ret.a = ((col & 0xff000000) >> 24) / 255.0;
return ret;
}

kryton9

I came up with a simple notion of how to go about with OOP programming and perhaps programming in c like languages compared to basic type ones.

Declare
Define
Use
Cleanup

So what this helps you to do is to think that when you do things in c and Aurora like languages you really need to think of these 4 things and check in those areas to make sure
you have what you need in each, if needed.

In playing with Paul's code, many times I was forgetting to go to the declare section and declare the new object I added down below in the code and would get errors. In going back and forth,
the thought above occured to me.

Ionic Wind Support Team

Ionic Wind Support Team