extras; samples: Fixed warnings
[sdk] / samples / 3D / walkAround / walkAround.ec
index 5af0fcf..0006983 100644 (file)
@@ -25,7 +25,7 @@ class WalkAroundApp : GuiApplication
          diffTime = time - lastTime;
          lastTime = time;
          GetMouseState(&buttons, &xd, &yd);
-         if(form)
+         if(form && form.active)
          {
             bool updateCamera = false;
             float speed = 50;
@@ -106,18 +106,20 @@ class WalkAroundForm : Window
    hasClose = true;
    clientSize = { 632, 438 };
 
-   Array<Material> materials { size = 8 };
+   Array<Material> materials { };
    Array<int> map { size = width * height };
    Array<int> elv { size = width * height };
-   Array<Color> colors { [ black, red, green, blue, cyan, magenta, white, gray, orange, yellow, brown, aquamarine, goldenrod ] };
    Array<Cube> cubes { };
 
+   BitmapResource spotTex { ":spot_tex.png", window = this };
    Material sideMat { opacity = 0.5f, diffuse = teal, ambient = teal, flags = { doubleSided = true, translucent = true } };
-   Material dolphin1Mat { opacity = 1.0f, diffuse = skyBlue, ambient = skyBlue };
-   Material dolphin2Mat { opacity = 1.0f, diffuse = lightGray, ambient = lightGray };
-   Object dolphinModel { };
-   Object dolphin1 { };
-   Object dolphin2 { };
+   Material cow1Mat { opacity = 1.0f, diffuse = white, ambient = white };
+   Material cow2Mat { opacity = 1.0f, power = 20, diffuse = goldenrod, ambient = goldenrod, specular = goldenrod };
+   Material cow3Mat { opacity = 1.0f, power = 20, diffuse = goldenrod, ambient = goldenrod, specular = goldenrod };
+   Object cowModel { };
+   Object cow1 { };
+   Object cow2 { };
+   Object cow3 { };
    Cube cube { };
    Array<Bitmap> textures { };
    bool acquiredInput;
@@ -133,7 +135,7 @@ class WalkAroundForm : Window
       int i;
       for(i = 0; i < map.count; i++)
       {
-         int num = map[i] = GetRandom(0, 7);
+         map[i] = GetRandom(0, 7);
          elv[i] = GetRandom(1, 100);
       }
    }
@@ -142,24 +144,35 @@ class WalkAroundForm : Window
    {
       Bitmap textureFile { };
       int i, x, y;
-      PrimitiveGroup group;
-
-      dolphinModel.Load(":dolphin.3ds", null, displaySystem);
-      dolphinModel.Merge(displaySystem);
-      dolphinModel.mesh.ApplyMaterial(null);
-
-      dolphin1.Duplicate(dolphinModel);
-      dolphin1.transform.position = { -20, -50, 10 };
-      dolphin1.transform.scaling = { 0.2, 0.2, 0.2 };
-      dolphin1.UpdateTransform();
-      dolphin1.material = dolphin1Mat;
-
-      dolphin2.Duplicate(dolphinModel);
-      dolphin2.transform.position = { 60, -30, -5 };
-      dolphin2.transform.scaling = { 0.2, 0.2, 0.2 };
-      dolphin2.UpdateTransform();
-      dolphin2.material = dolphin2Mat;
 
+      cowModel.Load(":cow.3DS", null, displaySystem);
+      cowModel.Merge(displaySystem);
+      cowModel.mesh.ApplyMaterial(null);
+
+      cow1.Duplicate(cowModel);
+      cow1.transform.position = { -20, -50, 10 };
+      cow1.transform.scaling = { 20, 20, 20 };
+      cow1.transform.orientation = Euler { yaw = 135 };
+      cow1.UpdateTransform();
+      cow1.material = cow1Mat;
+      cow1Mat.baseMap = spotTex.bitmap;
+
+      cow2.Duplicate(cowModel);
+      cow2.transform.position = { 60, -42, -5 };
+      cow2.transform.scaling = { 20, 20, 20 };
+      cow2.transform.orientation = Euler { yaw = 225 };
+      cow2.UpdateTransform();
+      cow2.material = cow2Mat;
+
+      cow3.Duplicate(cowModel);
+      cow3.transform.position = { 120, -89, 13 };
+      cow3.transform.scaling = { 20, 20, 20 };
+      cow3.transform.orientation = Euler { yaw = 185 };
+      cow3.UpdateTransform();
+      cow3.material = cow3Mat;
+      cow3Mat.baseMap = spotTex.bitmap;
+
+      materials.size = 8;
       if(textureFile.Load(":texture1.pcx", null, null))
       {
          int count = 8;
@@ -189,8 +202,6 @@ class WalkAroundForm : Window
          {
             int ix = y * width + x;
             int num = map[ix];
-            int xs = -((tileSize+gap) * width) / 2;
-            int ys = -((tileSize+gap) * height) / 2;
             float h = elv[ix];
             Cube cube { };
 
@@ -213,11 +224,15 @@ class WalkAroundForm : Window
 
    void OnUnloadGraphics()
    {
+      materials.Free();
+      textures.Free();
+
       for(c : cubes)
          c.Free(displaySystem);
-      dolphinModel.Free(displaySystem);
-      dolphin1.Free(displaySystem);
-      dolphin2.Free(displaySystem);
+      cowModel.Free(displaySystem);
+      cow1.Free(displaySystem);
+      cow2.Free(displaySystem);
+      cow3.Free(displaySystem);
       cubes.Free();
    }
 
@@ -237,8 +252,9 @@ class WalkAroundForm : Window
       for(c : cubes)
          display.DrawObject(c);
 
-      display.DrawObject(dolphin1);
-      display.DrawObject(dolphin2);
+      display.DrawObject(cow1);
+      display.DrawObject(cow2);
+      display.DrawObject(cow3);
 
       display.SetCamera(surface, null);
 
@@ -290,9 +306,13 @@ class WalkAroundForm : Window
                state = normal;
                anchor = { };
                clientSize = { 632, 438 };
-               position = position;
             }
             app.fullScreen = fullScreen;
+            if(fullScreen)
+               ; // app.resolution = res640x480;
+            else
+               position = position;
+
             AcquireInput(acquiredInput);
             break;
          }