IonicWind Software

Aurora Compiler => 3D Graphics => Topic started by: John S on August 10, 2006, 11:04:11 AM

Title: 3d Star System
Post by: John S on August 10, 2006, 11:04:11 AM
I took Paul's starfield example and tweaked it.  I have renamed "planet" to "star" and resized it.  I added an orbitting planet and moon (simple circular orbits only).

Camera controls are:
Up Arrow = rotate camera up
Dn Arrow = rotate camera down
Left Arrow = rotate camera left
Right Arrow = rotate camera right

V = Move Camera Forward
C = Move Camera Backward
Z = Roll Camera Counter Clockwise
X = Roll Camera Clockwise
A = Slide Camera Left
S = Slide Camera Right
E = Slide Camera Up
D = Slide Camera Down

R = Turn Camera towards Star
P = Turn Camera towards Planet             // edit
M = Turn Camera towards Moon             // edit


Paul,
how do I change the lighting controls.  I want star to be bright and shine on the planet and moon.


edit:  added M & P controls
Title: Re: 3d Star System
Post by: Ionic Wind Support Team on August 10, 2006, 11:05:04 AM
Forget to attach it?
Title: Re: 3d Star System
Post by: John S on August 10, 2006, 11:07:25 AM
not only forgot attachment, but editted and attached the wrong one.  Need more coffee! ;)
Title: Re: 3d Star System
Post by: John S on August 10, 2006, 11:25:52 AM
I added M & P controls so you can literally chase the moon or planet.

I plan on using this to create an asteroids game and a moon lander game.
Title: Re: 3d Star System
Post by: Ionic Wind Support Team on August 10, 2006, 11:49:54 AM
Nice work for someone new to 3D ;)
Title: Re: 3d Star System
Post by: John S on August 10, 2006, 12:05:56 PM
thanks Paul,
How do the lighting controls work?   I want the star to be bright and shine on the planet and moon.

light.Create(s,LIGHT_POINT,1);                      //  can I use LIGHT_SPHERE and spec a radius?
light.Position(0,0,0);                                      //  center of star
light.SetAttenuation(0,1/4000.0,0);                //  ?
light.SetSpecular(.5,.5,.5,1);                          //  ?
light.SetAmbient(.15,.15,.15,1);                     //  ?

I also have changed the star field portion to eliminate stars within the planet's orbit region (not uploaded yet).
Title: Re: 3d Star System
Post by: Ionic Wind Support Team on August 10, 2006, 12:12:40 PM
I'll go into lighting details when I get back from work. 
Title: Re: 3d Star System
Post by: Steven Picard on August 10, 2006, 12:20:13 PM
I'm anxious to try this out when I get home.
Title: Re: 3d Star System
Post by: John S on August 10, 2006, 02:48:17 PM
I revised the star, planet and moon textures.  I have included the source, textures and the exe file in the zip file.
I have to work now ;)  bye bye
Title: Re: 3d Star System
Post by: kryton9 on August 10, 2006, 04:30:27 PM
Nice :)

You have to move the media files in case anyone has a problem with the zip. Either put everything into the same folder, or make sure you set the path to where the textures are.
Title: Re: 3d Star System
Post by: Ionic Wind Support Team on August 10, 2006, 05:15:23 PM
About lights:

A light in d3d has many properties.  There are three kinds of lights you can use:

LIGHT_POINT
Light is a point source. The light has a position in space and radiates light in all directions.

LIGHT_SPOT
Light is a spotlight source. This light is like a point light, except that the illumination is limited to a cone. This light type has a direction and several other parameters that determine the shape of the cone it produces.

LIGHT_DIRECTIONAL
Light is a directional light source. This is equivalent to using a point light source at an infinite distance.

If you look at the 3D users guide you can see the methods you can use to adjust a lights properties. 

SetAmbient
     Ambient color emitted by the light.  Ambient light affects all objects equally. It does not create shadows and is additive in the scene. Each light you and emmissive object will add ambient lighting.

SetAttenuation
    Attenuation controls how a light's intensity decreases toward the maximum distance specified by the range property. Three parameters of this method represent light attenuation: Att0, Att1, and Att2. These members contain floating-point values ranging from 0.0 through infinity, controlling a light's attenuation. Some applications set the Attenuation1 member to 1.0 and the others to 0.0, resulting in light intensity that changes as 1 / D, where D is the distance from the light source to the vertex. The maximum light intensity is at the source, decreasing to 1 / (Light Range) at the light's range. Typically, an application sets Attenuation0 to 0.0, Attenuation1 to a constant value, and Attenuation2 to 0.0.

You can combine attenuation values to get more complex attenuation effects. Or, you might set them to values outside the normal range to create even stranger attenuation effects. Negative attenuation values, however, are not allowed

SetDiffuse
     Diffuse color emitted by the light.  The diffuse color is used in shading calculations.  The diffuse color of a mesh is specified by either a member of the vertex structure, or a material.

SetFalloff
     Decrease in illumination between a spotlight's inner cone (the angle specified by Theta) and the outer edge of the outer cone (the angle specified by Phi). The effect of falloff on the lighting is subtle. Furthermore, a small performance penalty is incurred by shaping the falloff curve. For these reasons, most developers set this value to 1.0.

SetPhi
    Angle, in radians, defining the outer edge of the spotlight's outer cone. Points outside this cone are not lit by the spotlight. This value must be between 0 and pi.

SetRange
   Distance beyond which the light has no effect. The maximum allowable value for this member is the square root of FLT_MAX. This member does not affect directional lights.

SetSpecular
     Specular color emitted by the light.  Specular components of a mesh are normally specified in a material.

SetTheta
    Angle, in radians, of a spotlight's inner coneâ€ââ,¬Âthat is, the fully illuminated spotlight cone. This value must be in the range from 0 through the value specified by Phi.

That is the very basic information about lighting.  Hope it helps a bit.

Paul.
Title: Re: 3d Star System
Post by: John S on August 10, 2006, 06:12:11 PM
thanks Paul,
I tweaked the light.SetAttenuation(0,1/1000.0,0); parameter and got shadowing on the far side of the planet and moon.
How do I get the planet to cast a shadow on the moon and vise versa?


star.CreateSphere(s,25,50.0,false);
star.LoadTexture(0,GetStartPath()+"sun.tga",0);

planet.CreateSphere(s,25,15.0,false);
planet.LoadTexture(0,GetStartPath()+"planet.tga",0);

moon.CreateSphere(s,25,3.0,false);
moon.LoadTexture(0,GetStartPath()+"moon.tga",0);

light.Create(s,LIGHT_POINT,1);
light.Position(0,0,0);
light.SetAttenuation(0,1/1000.0,0);
light.SetSpecular(.5,.5,.5,1);
light.SetAmbient(.15,.15,.15,1);

scene.CreateScene(s);
scene.AddChild(light);
scene.AddChild(m);
scene.AddChild(star);
scene.AddChild(planet);
scene.AddChild(moon);
Title: Re: 3d Star System
Post by: Ionic Wind Support Team on August 10, 2006, 07:05:36 PM
DirectX lighting doesn't work like that.  Objects don't 'block' light.  Shadows have to be created another way which we have yet to get into.
Title: Re: 3d Star System
Post by: Steven Picard on August 10, 2006, 09:01:57 PM
I tried it out.  It's a very good start.