March 29, 2024, 08:36:52 AM

News:

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


3d Star System

Started by John S, August 10, 2006, 11:04:11 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

John S

August 10, 2006, 11:04:11 AM Last Edit: August 10, 2006, 11:24:25 AM by John S
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
John Siino, Advanced Engineering Services and Software

Ionic Wind Support Team

Ionic Wind Support Team

John S

not only forgot attachment, but editted and attached the wrong one.  Need more coffee! ;)
John Siino, Advanced Engineering Services and Software

John S

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.
John Siino, Advanced Engineering Services and Software

Ionic Wind Support Team

Nice work for someone new to 3D ;)
Ionic Wind Support Team

John S

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).
John Siino, Advanced Engineering Services and Software

Ionic Wind Support Team

I'll go into lighting details when I get back from work. 
Ionic Wind Support Team

Steven Picard

I'm anxious to try this out when I get home.

John S

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
John Siino, Advanced Engineering Services and Software

kryton9

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.

Ionic Wind Support Team

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.
Ionic Wind Support Team

John S

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);
John Siino, Advanced Engineering Services and Software

Ionic Wind Support Team

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.
Ionic Wind Support Team

Steven Picard

I tried it out.  It's a very good start.