May 02, 2024, 03:49:28 PM

News:

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


HELP!!!!

Started by J B Wood (Zumwalt), July 26, 2006, 08:20:02 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

J B Wood (Zumwalt)

OK I am freakingout, I need a SUN light with a max lighting!
And I need it ASAP!!!

WHat do I set the lighting to and what distance, I also am moving the camera..
I have a terrain, let me just say, state size...
There is no other game engine I own that would load it, this one DOES!!!!!

However, I can't seem to figure out the lighting to make it light up!!!

*breath zum, breath*

Barney

Try with directional light or even better with spot light positioned just above your model. If the model does not want to lit up check check the normals...

Barney

Ionic Wind Support Team

OK first of all if you're not using textures then you have to set up the mesh to use vertex lighting.

mesh.UserVertexColor(true);

If you are using a texture for the 3DS object then turn vertex coloring off.

When creating a light set the attenuation to something small first.  In the examples directory is a small program that loads a 3ds park.  Here is the light it uses:


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);


Ionic Wind Support Team

J B Wood (Zumwalt)

Thanks, I'll give these a try tonight.
Second delima, I broke my terrain down to 15x15 quadrants.
So, what I want to do, is using Aurora, load each terrain quadrant as I approach the edge of the one I am at based on the LOD designed distance, or just load the adjacent terrains to the current quadrant.


123456789101112131415
2
3
4
5
6
7
8
9
10
11
12
13
14
15

I would post the terrain data, but compressed its around 260 megs, and its either stuck uploading to my FTP or my uploaded ended early at the house, which bites.

J B Wood (Zumwalt)

Here is an image of a terrain I just made, its an terrain made up of the following components:

64x64 Tiles
8x8 Quadrants
512x512 Segments

Ionic Wind Support Team

260M?

Why not just use the landscape object?.  It will keep your memory requirements down and already has automatic quadtree culling.

Ionic Wind Support Team

J B Wood (Zumwalt)

Probably because I haven't tried it yet and don't know how to use it :)
To put the size of this terrain I need into perspective, here is an example running in your engine.
Note the size of the robot in the lower left corner at the moment :)


Ionic Wind Support Team

Well the first thing you can do to speed up rendering is build an octree from the mesh.  Depending on the poly count you'll need to experiment for best values.  Try:

mesh.BuildOctree(500,4);

To begin with.  The first number is the number of polys per block and the second is how deep the scanner will go to subdivide it even more.

---------------

The paramteres to the built in landscape object are described as such:

heightMapFile This is the height map image file. The height of a corner of each block in the landscape calculated from the red component of the pixel corresponding to that point on the map. 255 is the highest point, with y value = maxBlockHeight, 127 being the point with y value = 0, 0 being the lowest point with y value roughly equal to -maxBlockHeight.

If the heightMapFile image has dimension Row x Column, the landscape will has (Row - 1) x (Column - 1) blocks. This is because four nearby points form a block:

a----b----c     When the heightMapFile is 3x3 and
|  1 |  2 |     a, b, c, d, e, f, g, h, i are the corners,
d----e----f     There will be a total of 4 blocks in
|  3 |  4 |     the landscape generated
g----h----i

lightMapFileThis is the light map that specifies the brightness of each corner of the landscape. This can be use to achieve a shadow effect. The lightMapFile must have the same dimemsions as heightMapFile.

When the useGrayScaleLightMap flag is true, only the red component of the light map is used to determine the brightness.

When the useGrayScaleLightMap flag is false, all the components of light map will be use to blend with the pixel color, so you can create the effect of colored light.

coverageFile This is the file that is used to specify how much of each texture should be used to render each corner of the lanscape. The red, green, blue component of each pixel represents the amount of tile1, tile2, tile3 respectively. The pixel color, before being modulated by the light map, is calculated using this formula:

(r / 255)*t1 + (g / 255)g*t2 + (b / 255)*t2

where r, g, b are the red, green, blue components of the coverage factor pixel. t1, t2, t3 are the color of the three textures tile1, tile2, and tile3 respectively.

Note that this is a weighted average, therefore, to make the pixel color "complete", (r + g + b) MUST equal 255

tile1File The first texture files that are used for texture blending.
tile2File The second texture files that are used for texture blending.
tile3File The third texture files that are used for texture blending.
blockSizeX The size of each block of the landscape along x axis
blockSizeZ The size of each block of the landscape along z axis
maxBlockHeight Maximum height of the landscape that value 255 in the height map corresponds to
textureScaleX The scale of texture along width, which is mapped to X axis of a block in the landscape.
textureScaleZ The scale of texture along height, which is mapped to Z axis of a block in the landscape.
useGrayscaleLightMap Flag that specifies whether the light map is grayscale or color.

The landscape object was based on this article:

http://www.delphi3d.net/articles/viewarticle.php?article=terraintex.htm

Have fun,
Paul.
Ionic Wind Support Team

J B Wood (Zumwalt)

So, in theory, I should be able to use just your engine, a height map file and a color map file to generate an 8 quadrant x 8 quadrant terrain with 512x512 blocks per quadrant that each have 64x64 blocks within them automatically and end up with the same image I am showing?

Ionic Wind Support Team

Yes  But the size of your terrain is remarkably big. 
Ionic Wind Support Team

kryton9

July 27, 2006, 05:45:17 PM #10 Last Edit: July 27, 2006, 05:51:16 PM by kryton9
Posting this here as I need help too :)

I don't understand why this isn't working?
I made s global and if I don't use it in the function ksHelp, it works fine.
I want to put all the help for a model viewer I will try to make and I want it outside of the main function.

//Skinned X example
//Arrow keys to move camera.
//PgUp/PgDn to pan up and down.
//Z and X to rotate on Z axis.

declare import,timeGetTime(),int;
declare ksHelp ();
global s;
global sub main()
{
ÂÃ,  ÂÃ, C3DScreen s;
ÂÃ,  ÂÃ, C3DCamera c;
ÂÃ,  ÂÃ, C3DMesh m;
ÂÃ,  ÂÃ, C3DObject scene;
ÂÃ,  ÂÃ, C3DLight light;
ÂÃ,  ÂÃ, CDirectInput di;
ÂÃ,  ÂÃ, float fadjust,fTarget;
ÂÃ,  ÂÃ, //target 60FPS for camera movement
ÂÃ,  ÂÃ, fTarget = 1.0f / /*FPS*/60.0f * 1000.0f;
ÂÃ,  ÂÃ, fAdjust = 1.0f;
ÂÃ,  ÂÃ, 
ÂÃ,  ÂÃ, s.CreateWindowed(0,0,800,600,AWS_CAPTION|AWS_VISIBLE|AWS_SIZE|AWS_CENTERED,0,"Skinned X example - ESC exits",NULL,false);
ÂÃ,  ÂÃ, di.Init(s);
ÂÃ,  ÂÃ, c.Create(s);
ÂÃ,  ÂÃ, c.Position(0,0,-700);
ÂÃ,  ÂÃ, c.Orient(0,0,1,0,1,0);
ÂÃ,  ÂÃ, c.SetBackPlane(10000);
ÂÃ,  ÂÃ, 
ÂÃ,  ÂÃ, s.Clear(RGBA(0,0,0,255));
ÂÃ,  ÂÃ, s.BeginScene(c);
ÂÃ,  ÂÃ, s.RenderText(0,10,"Loading objects...",RGBA(255,255,0,255));
ÂÃ,  ÂÃ, s.RenderScene();
ÂÃ,  ÂÃ, 
ÂÃ,  ÂÃ, m.LoadSkinnedX(s,GetStartPath() + "media\\tiny.x");
ÂÃ,  ÂÃ, m.SetAnimation(0,0,800,timeGetTime());
ÂÃ,  ÂÃ, 
ÂÃ,  ÂÃ, light.Create(s,LIGHT_POINT,1);
ÂÃ,  ÂÃ, light.Position(0,100,-300);
ÂÃ,  ÂÃ, light.SetAttenuation(0,1/200.0,0);
ÂÃ,  ÂÃ, light.SetSpecular(.5,.5,.5,1);
ÂÃ,  ÂÃ, light.SetAmbient(.4,.4,.4,1);
ÂÃ,  ÂÃ, 
ÂÃ,  ÂÃ, scene.CreateScene(s);
ÂÃ,  ÂÃ, scene.AddChild(light);
ÂÃ,  ÂÃ, scene.AddChild(m);
ÂÃ,  ÂÃ, int fps = 0;
ÂÃ,  ÂÃ, int startTime;
ÂÃ,  ÂÃ, do
ÂÃ,  ÂÃ, {
ÂÃ,  ÂÃ,  ÂÃ,  startTime = timeGetTime();
ÂÃ,  ÂÃ,  ÂÃ,  //check for keys and move camera accordingly
ÂÃ,  ÂÃ,  ÂÃ,  IF di.KeyDown(DIK_UP)
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, c.Move(0.0f,10f * fAdjust);
ÂÃ,  ÂÃ,  ÂÃ,  IF di.KeyDown(DIK_DOWN)
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, c.Move(0.0f,-10f * fAdjust);
ÂÃ,  ÂÃ,  ÂÃ,  IF di.KeyDown(DIK_RIGHT)
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, c.Rotate(1*.01745 * fAdjust,0,0);
ÂÃ,  ÂÃ,  ÂÃ,  IF di.KeyDown(DIK_LEFT)
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, c.Rotate(-1*.01745 * fAdjust,0,0);
ÂÃ,  ÂÃ,  ÂÃ,  IF di.KeyDown(DIK_Z)
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, c.Rotate(0,0,-1 *.01745 * fAdjust);
ÂÃ,  ÂÃ,  ÂÃ,  IF di.KeyDown(DIK_X)
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, c.Rotate(0,0,1 *.01745 * fAdjust);
ÂÃ,  ÂÃ,  ÂÃ,  IF di.KeyDown(DIK_PRIOR)
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, c.Rotate(0,-1 *.01745 * fAdjust,0);
ÂÃ,  ÂÃ,  ÂÃ,  IF di.KeyDown(DIK_NEXT)
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, c.Rotate(0,1 *.01745 * fAdjust,0);
ÂÃ,  ÂÃ,  ÂÃ,  IF di.KeyDown(DIK_R)
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, c.LookAt(0,0,10000);
ÂÃ,  ÂÃ,  ÂÃ, 
ÂÃ,  ÂÃ,  ÂÃ,  s.Clear(RGBA(0,0,0,255));
ÂÃ,  ÂÃ,  ÂÃ,  s.BeginScene(c);
ÂÃ,  ÂÃ,  ÂÃ,  m.UpdateAnimation(timeGetTime());
ÂÃ,  ÂÃ,  ÂÃ,  scene.Draw();
ÂÃ,  ÂÃ,  ÂÃ,  s.RenderText(0,10,"FPS:"+NumToStr(fps),RGBA(255,255,0,255));
ÂÃ,  ÂÃ,  ÂÃ,  s.RenderText(0,30,"Use arrow keys to move around",RGBA(255,255,0,255));
ÂÃ,  ksHelp();
ÂÃ,  ÂÃ,  ÂÃ,  fps = s.RenderScene();
ÂÃ,  ÂÃ,  ÂÃ,  fAdjust = (timeGetTime() - startTime) / fTarget;
ÂÃ,  ÂÃ, }until di.KeyDown(DIK_ESCAPE);
ÂÃ,  ÂÃ, Scene.Free();
}

sub ksHelp()
{
s.RenderText(0,80,"ksHelp: "+"test to see if working",RGBA(255,255,0,255));
}


I tried this too and it builds with no errors, but then the program crashes with a send a report to microsoft.
//Skinned X example
//Arrow keys to move camera.
//PgUp/PgDn to pan up and down.
//Z and X to rotate on Z axis.

declare import,timeGetTime(),int;
declare ksHelp ();
C3DScreen s;
global s;
global sub main()
{
   //C3DScreen s;
   C3DCamera c;
   C3DMesh m;
   C3DObject scene;
   C3DLight light;
   CDirectInput di;
   float fadjust,fTarget;
   //target 60FPS for camera movement
   fTarget = 1.0f / /*FPS*/60.0f * 1000.0f;
   fAdjust = 1.0f;
   
   s.CreateWindowed(0,0,800,600,AWS_CAPTION|AWS_VISIBLE|AWS_SIZE|AWS_CENTERED,0,"Skinned X example - ESC exits",NULL,false);
   di.Init(s);
   c.Create(s);
   c.Position(0,0,-700);
   c.Orient(0,0,1,0,1,0);
   c.SetBackPlane(10000);
   
   s.Clear(RGBA(0,0,0,255));
   s.BeginScene(c);
   s.RenderText(0,10,"Loading objects...",RGBA(255,255,0,255));
   s.RenderScene();
   
   m.LoadSkinnedX(s,GetStartPath() + "media\\tiny.x");
   m.SetAnimation(0,0,800,timeGetTime());
   
   light.Create(s,LIGHT_POINT,1);
   light.Position(0,100,-300);
   light.SetAttenuation(0,1/200.0,0);
   light.SetSpecular(.5,.5,.5,1);
   light.SetAmbient(.4,.4,.4,1);
   
   scene.CreateScene(s);
   scene.AddChild(light);
   scene.AddChild(m);
   int fps = 0;
   int startTime;
   do
   {
      startTime = timeGetTime();
      //check for keys and move camera accordingly
      IF di.KeyDown(DIK_UP)
         c.Move(0.0f,10f * fAdjust);
      IF di.KeyDown(DIK_DOWN)
         c.Move(0.0f,-10f * fAdjust);
      IF di.KeyDown(DIK_RIGHT)
         c.Rotate(1*.01745 * fAdjust,0,0);
      IF di.KeyDown(DIK_LEFT)
         c.Rotate(-1*.01745 * fAdjust,0,0);
      IF di.KeyDown(DIK_Z)
         c.Rotate(0,0,-1 *.01745 * fAdjust);
      IF di.KeyDown(DIK_X)
         c.Rotate(0,0,1 *.01745 * fAdjust);
      IF di.KeyDown(DIK_PRIOR)
         c.Rotate(0,-1 *.01745 * fAdjust,0);
      IF di.KeyDown(DIK_NEXT)
         c.Rotate(0,1 *.01745 * fAdjust,0);
      IF di.KeyDown(DIK_R)
         c.LookAt(0,0,10000);
     
      s.Clear(RGBA(0,0,0,255));
      s.BeginScene(c);
      m.UpdateAnimation(timeGetTime());
      scene.Draw();
      s.RenderText(0,10,"FPS:"+NumToStr(fps),RGBA(255,255,0,255));
      s.RenderText(0,30,"Use arrow keys to move around",RGBA(255,255,0,255));
  ksHelp();
      fps = s.RenderScene();
      fAdjust = (timeGetTime() - startTime) / fTarget;
   }until di.KeyDown(DIK_ESCAPE);
   Scene.Free();
}

sub ksHelp()
{
//s.RenderText(0,80,"ksHelp: "+"test to see if working",RGBA(255,255,0,255));
}

Ionic Wind Support Team

It's not working because you're not using it correctly.

You can't make a local variable global.  Local variables are stored on the stack and are not handled by the linker. The 'global' keyword is only used to make functions and variables defined at file scope visible to other source files in your program.  so you can use the 'extern' keyword in another source file to reference it.

You can make a pointer to a local varaible though,

C3DScreen *gpScreen;

global sub main()
{
     ....
     gpScreen = &s;
}

However in your example your making it too complicated.  Just use a parameter to your funciton.

sub ksHelp(C3DScreen *pScreen)
{
pScreen->RenderText(0,80,"ksHelp: "+"test to see if working",RGBA(255,255,0,255));
}


And in your main subroutine it would be:

  ksHelp(s);

Easy.

Paul.
Ionic Wind Support Team

kryton9

Thanks Paul, yes it is easy when you explain it. Glad I don't have to keep declaring it everywhere.

Is this a good rule then, That if you need to access something outside of where it is being declared, defined and used then to make it a pointer?


kryton9

Paul, thanks again, it worked wether I declared my function or not? Is that ok to go without it then or to do it this way, where you declare it at the top:
declare import,timeGetTime(),int;
declare ksHelp (C3DScreen *pScreen);
C3DScreen *gpScreen;
global sub main()
{
   C3DScreen s;
   gpScreen = &s;
.
.
.
}
sub ksHelp(C3DScreen *pScreen)
{
   pScreen->RenderText(0,80,"ksHelp: "+"test to see if working",RGBA(255,255,0,255));
}

Ionic Wind Support Team

Depends on the application, and what the data is.  All up to you.

If you have a bunch of functions use paramters.  Overuse of global variables is a bad thing, and not thread safe unless you use a locking mechanism.  Not that you need to worry about that unless your using threads.

My 3D examples are meant to be simple and just show off features of the engine.  I wouldn't actually write a game, or applcation, with everything located the main function.  For larger programs I normally write classes/subs on paper first before the first line of code gets typed in. But I am old school like that.

Then it depends on whether the language supports OOP or not.  Take a look at the frags2d example.  The main subroutine looks like this:


global sub main ()
{
TheApp app;
app.Run();
}


Which just defines an instance of the app class and calls the Run method.  So everything else is done in oop and I don't need to worry about procedural code then. 

Member variables are used instead of global ones.  And the app class is treated as a mini program in and of it self.  Which is one way to think of it.



Ionic Wind Support Team

Ionic Wind Support Team

Quote from: kryton9 on July 27, 2006, 06:04:42 PM
Paul, thanks again, it worked wether I declared my function or not? Is that ok to go without it then or to do it this way....

Aurora is a two pass compiler.  There is no need to declare a function unless you require the cdecl calling convention.  Or if your declaring an external function located in a different source/object file.
Ionic Wind Support Team

kryton9

Ok, great. Also about the procedural route vrs oop, I guess I just slipped into the old way of thinking... you are right I should make everything classes. Which means, it will be awhile before I get around to writing the model viewer. As got lots toooo learn :)

kryton9

QuoteThen it depends on whether the language supports OOP or not.  Take a look at the frags2d example.

Looking at the frags2d and now at least the class sort of stuff is not as frightening, but saw something that I still can't figure where it is coming from.

frags.Create();
frags.GetFirst();

there are many more functions like this after frags, and I can't seem to see where they are in the program defining what they do or where they came from?

Ionic Wind Support Team

Frags is a linked list.  It is a class member variable.


class TheApp
{
declare TheApp();
declare _TheApp();
declare CreateFrags(int mx,int my);
declare UpdateFrags();
declare RenderFrags();
declare Run(),int;
//variable of the app
C2DScreen screen;
CPointerList frags;   //<<<<<<<<
float gravity;
int ptx,pty,speed;
}
Ionic Wind Support Team

kryton9

I can't find the following include file.

I own the source and of course Aurora and nowhere to be found. I am trying to really brush up the 3d stuff and a lot of things tie into that I think?

dx3d.inc
Also one more thing... I have been trying since last night to get the animation to play once and stop, or to do the ping pong.

I did figure out how to stop and to loop and to also change the speed of the animation while looping.

Thanks

Ionic Wind Support Team

The include file is just declares for the DLL and didn't make it into the source archive.  I mentioned that in the update thread already.

Not all animation modes work with X meshes.  The 'ping pong' and 'once' only works for MD2 meshes.

Ionic Wind Support Team

kryton9

August 02, 2006, 09:34:02 PM #21 Last Edit: August 02, 2006, 09:38:30 PM by kryton9
OK thanks,

Then I was reading about this on MSDN.

HRESULT D3DXComputeBoundingBox(
ÂÃ,  CONST D3DXVECTOR3 * pFirstPosition,
ÂÃ,  DWORD NumVertices,
ÂÃ,  DWORD dwStride,
ÂÃ,  D3DXVECTOR3 * pMin,
ÂÃ,  D3DXVECTOR3 * pMax
);

Can we access the pmin and pmax's in your routine, I didn't see where it returned anything.

I thought I could use that data to figure out where to automatically place the camera for any sized object :)

Or if you have a few seconds, can you show me how I can write my own aurora routine to use the above. please please pretty please. I really want to learn this stuff.

It you don't have the time, then can I derive a class from your class and add those elements into it?

Also if I can figure this stuff out would love to help with the 3d engine, no charge of course, just fun for me. My benefit is getting some guidance and maybe some more tips of good places to find info. It is hard.
I spend many wasted hours looking. But still fun doing so.

Also where does your programs sort of interface with direct x? Can you point me in a direction in the source files. Your bounding box doesn't look like theirs

Ionic Wind Support Team

Quote
Also where does your programs sort of interface with direct x? Can you point me in a direction in the source files. Your bounding box doesn't look like theirs

What are you talking about?  None of the 3D methods return a bounding box.  You could calculate one if you wanted to by reading each of the meshes vertexes and calculating the min/max of x,y and z.

The D3DX functions are not accessable from non Microsoft C++ code.  Which is why we use a DLL.  The DLL uses COM to access DirectX9.  And in the Linux version the classes will access OpenGL.



Ionic Wind Support Team

Ionic Wind Support Team

Quote
Also if I can figure this stuff out would love to help with the 3d engine, no charge of course, just fun for me.

Not looking for anyone at the moment.   Still working on the base of the engine anyway which is rendering and collision.  If you really want to learn DX9 then you'll need to download the SDK and fire up a C# compiler.  Or download an older version of the SDK and use VC++ 6.0 which is what we are using.

Ionic Wind Support Team

kryton9

Paul, is there info for the directx.dll for the com objects?

Also when you say older version of directx sdk, it is still directx 9, but can you give me a date to look for?

Thanks.