Lighting


Diffuse Lighting (Kd)

Diffuse lighting is a similar how the Sun illuminates the earth. In diffuse lighting, there se a light source located a great distance away from the objects in the scene. Diffuse lighting has a direction and a color.
La iluminación difusa es similar a cómo el Sol ilumina la tierra. En la iluminación difusa, hay una fuente de luz ubicada a una gran distancia de los objetos en la escena. La iluminación difusa tiene una dirección y un color.

Ambient Lighting (Ka)

Ambient lighting is a similar to the general light that there is in a place. In ambient lighting, the walls, the ceiling and the floor reflect some amount of light and provide a constant light coming from all directions. Ambient lighting has a color.
La iluminación ambiental es semejante a la luz general que hay en un lugar. En iluminación ambiental, las paredes, el techo y el piso reflejan una cierta cantidad de luz y proporcionan una luz constante llegando de todas direcciones. La iluminación ambiental tiene un color.

Specular Lighting (Ks)

Specular lighting is produced over shinning or polish surfaces like those in metal and ceramic. In specular lighting, the surface of an object may reflect a high amount of light in very specific parts of a 3D object depending on the position of the object as well as on the position of light source. The specular lighting has a color and an amount of power.
La iluminación especular es producida sobre superficies brillantes o pulidas como en aquellas de los metales o de las cerámicas. En la iluminación especular, la superficie de un objeto puede reflejar una cantidad alta de luz en partes muy específicas de un objeto 3D dependiendo de la posición del objeto así como también de la posición de la fuente de luz. La iluminación especular tiene un color y una cantidad de fuerza.

Shader

A shader is a program than runs in the GPU. A shader is written in High Level Shading Language (HLSL). The table shows the type of lighting support for each shader. Vertex shaders and pixel shaders are commonly stored in a HSLSL file (*.hlsl). Shaders are described in DirectX > Introduction.
Un shader es un programa que corre en la GPU. Un shader está escrito en High Level Shading Language (HLSL). La tabla muestra los tipos de iluminación de cada shader. Usted puede inspeccionar las clases que implementan los shaders. Los shaders de vértices y los shaders de pixeles son comúnmente almacenados en un archivo HLSL (*.hlsl). Los shaders están descritos en DirectX > Introduction.

Class    Objects with    Normal vector    Diffuse lighting    Ambient lighting    Specular lighting  
DX11::ColorShadercolorno requirednonono
DX11::ColorAmbientLightShadercolorrequiredyesyesno
DX11::ColorDiffuseLightShadercolorrequiredyesnono
DX11::ColorSpecularLightShadercolorrequiredyesyesyes
DX11::TextureShadertextureno requirednonono
DX11::TextureAmbientLightShadertexturerequiredyesyesno
DX11::TextureDiffuseLightShadertexturerequiredyesnono
DX11::TextureSpecularLightShadertexturerequiredyesyesyes

Tip
The table shows the type of vertex and vertex buffer for each shader.
La tabla muestra los tipos de vértices y buffer de vértices para cada shader.

Class    Vertex    VertexBuffer  
DX11::ColorShaderDX11::ColorVertexDX11::VertexBuffer
DX11::ColorAmbientLightShaderDX11::ColorNormVertexDX11::ColorNormVertexBuffer
DX11::ColorDiffuseLightShaderDX11::ColorNormVertexDX11::ColorNormVertexBuffer
DX11::ColorSpecularLightShaderDX11::ColorNormVertexDX11::ColorNormVertexBuffer
DX11::TextureShaderDX11::TextureVertexDX11::TextureVertexBuffer
DX11::TextureAmbientLightShaderDX11::TextureNormVertexDX11::TextureNormVertexBuffer
DX11::TextureDiffuseLightShaderDX11::TextureNormVertexDX11::TextureNormVertexBuffer
DX11::TextureSpecularLightShaderDX11::TextureNormVertexDX11::TextureNormVertexBuffer

Tip
The table shows the name of the shader object for the DX11::Engine.
La tabla muestra el nombre del objecto del shader para la DX11::Engine.

Class    DX11::Engine Name  
DX11::ColorShaderengine.shaderColor
DX11::ColorAmbientLightShaderengine.shaderColorAmbient
DX11::ColorDiffuseLightShaderengine.shaderColorDiffuse
DX11::ColorSpecularLightShaderengine.shaderColorSpecular
DX11::TextureShaderengine.shaderTextu
DX11::TextureAmbientLightShaderengine.shaderTextuAmbient
DX11::TextureDiffuseLightShaderengine.shaderTextuDiffue
DX11::TextureSpecularLightShaderengine.shaderTextuSpecular

Problem 1
Create a DirectX application using Wintempla called Cloud to test diffuse lighting in objects with solid colors. The program will draw three cubes, starting on the left, the first cube has diffuse lighting, the second cube has ambient and diffuse lighting, while the last one has ambient, diffuse and specular lighting. After creating the project, add a DirectX object called Figure and a DirectX scene called MainScene. You may try to use other geometric figures using the tessellator.
Cree una aplicación de DirectX usando Wintempla llamada Cloud para probar la iluminación difusa en objetos con colores sólidos. El programa dibujará tres cubos, empezando en la izquierda, el primer cubo tiene iluminación difusa, el segundo cubo tiene luz ambiental y difusa, mientras que el último tiene iluminación ambiental, difusa y especular. Después de crear el proyecto, agregue un objeto de DirectX llamado Figure y una escena de DirectX llamada MainScene. Usted puede tratar de usar otras figuras geométricas usando el tesselator.

CloudRun1

CloudRun2

CloudRun3

CloudPolygon

CloudPrism

CloudCilinder

CloudPiramid

CloudCone

CloudSphere

CloudTetra

CloudOcta

CloudDodeca

CloudIcosa

Figure.h
//____________________________________________________________ Figure.h
#pragma once

#define LIGHT_AMBIENT 0
#define LIGHT_DIFFUSE 1
#define LIGHT_SPECULAR 2

class Figure : public DX11::Object3D
{
public:
     float x = 0.0f, y = 0.0f, z = 0.0f;
     float angleY = 0.0f;
     DirectX::XMMATRIX scale = DirectX::XMMatrixScaling(0.6f, 0.6f, 0.6f); //DirectX::XMMatrixIdentity();
     DirectX::XMFLOAT4 color = DirectX::XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f); // Green
     int light = LIGHT_AMBIENT;
     bool OnCreateScene(DX11::Engine& engine);
     . . .
};


Figure.cpp
. . .
void Figure::OnUpdate(DX11::Engine& engine, float sec, float deltaSec)
{
     angleY += (0.5f*deltaSec);
     world = DirectX::XMMatrixRotationY(angleY);
     DirectX::XMMATRIX translation = DirectX::XMMatrixTranslation(x, y, z);
     world = DirectX::XMMatrixMultiply(world, translation);
     world = DirectX::XMMatrixMultiply(scale, world);
     if (angleY > DirectX::XM_2PI) angleY -= DirectX::XM_2PI;
}

void Figure::OnRender3D(DX11::Engine& engine)
{
     if (light == LIGHT_AMBIENT)
     {
          engine.shaderColorAmbient.Render(engine, world, vertexBuffer->GetIndexCount(), 0, 0);
     }
     else if (light == LIGHT_DIFFUSE)
     {
          engine.shaderColorDiffuse.Render(engine, world, vertexBuffer->GetIndexCount(), 0, 0);
     }
     else // LIGHT_SPECULAR
     {
          engine.shaderColorSpecular.Render(engine, world, vertexBuffer->GetIndexCount(), 0, 0);
     }
}
. . .


MainScene.h
//____________________________________________________________ MainScene.h
#pragma once
#include "Figure.h"

class MainScene : public DX11::Scene
{
public:
     Figure figure[3];
     void OnCreateScene(DX11::Engine& engine);
     . . .
};


MainScene.cpp
. . .
void MainScene::OnCreateScene(DX11::Engine& engine)
{
     //_______________________________________ 1. Set back color RGBA
     this->SetBackColor(0.0f, 0.0f, 0.4f, 1.0f);
     //_______________________________________ 2.Set figure position
     figure[0].x = 0.0f;
     figure[1].x = -1.8f;
     figure[2].x = 1.8f;
     //_______________________________________ 3.Set figure color
     figure[0].color = DirectX::XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f);
     figure[1].color = DirectX::XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f);
     figure[2].color = DirectX::XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f);
     //_______________________________________ 4. Set light
     figure[0].light = LIGHT_AMBIENT;
     figure[1].light = LIGHT_DIFFUSE;
     figure[2].light = LIGHT_SPECULAR;
     //_______________________________________ 5. Set children of scene
     this->AddChild(figure[0]);
     this->AddChild(figure[1]);
     this->AddChild(figure[2]);
     //_______________________________________ 6. Camera setup
     . . .
}

void MainScene::OnUpdate(DX11::Engine& engine, float sec, float deltaSec)
{
     //__________________________________________________ 1. Move camera with keyboard
     if (engine.keyboard[VK_UP]) camera.position.y -= deltaSec;
     if (engine.keyboard[VK_DOWN]) camera.position.y += deltaSec;
     if (engine.keyboard[VK_LEFT]) camera.position.x += deltaSec;
     if (engine.keyboard[VK_RIGHT]) camera.position.x -= deltaSec;
     //__________________________________________________ 2. Move camera with mouse wheel
     if (engine.poitingDevice.distanceWheelRotated > 10)
     {
          camera.position.z -= (10.0f*deltaSec);
     }
     else if (engine.poitingDevice.distanceWheelRotated < -10)
     {
          camera.position.z += (10.0f*deltaSec);
     }
     camera.Update();
}
. . .


Cloud.h
#pragma once //______________________________________ Cloud.h
#include "Resource.h"
#include "MainScene.h"

class Cloud : public DX11::Window
{
public:
     MainScene mainScene;
     DX11::ColorNormVertexBuffer vbRed;
     DX11::ColorNormVertexBuffer vbGreen;
     DX11::ColorNormVertexBuffer vbBlue;
};


Cloud.cpp
. . .
int APIENTRY wWinMain(HINSTANCE hinst, HINSTANCE , LPTSTR c, int cshow)
{
     Cloud app;
     //_________________________________________________________ 1. Create vertex buffers
     vector<valarray<Sys::Vertex> > mesh;
     Sys::Tessellator tessellator;
     tessellator.GenerateBox(mesh);
     //tessellator.GeneratePolygon(5, mesh);
     //tessellator.GeneratePrism(5, mesh);
     //tessellator.GenerateCilinder(20, mesh);
     //tessellator.GeneratePiramid(5, mesh);
     //tessellator.GenerateCone(20, mesh);
     //tessellator.GenerateSphere(3, mesh);
     //tessellator.GenerateTetrahedron(mesh);
     //tessellator.GenerateOctahedron(mesh);
     //tessellator.GenerateDodecahedron(mesh);
     //tessellator.GenerateIcosahedron(mesh);
     app.vbRed.CreateData(mesh, DirectX::XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f), false);
     app.vbGreen.CreateData(mesh, DirectX::XMFLOAT4(0.0f, 1.0f, 0.0f, 1.0f), false);
     app.vbBlue.CreateData(mesh, DirectX::XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f), false);
     //_________________________________________________________ 2. Add vertex buffers to the engine
     app.engine.AddChild(app.vbRed);
     app.engine.AddChild(app.vbGreen);
     app.engine.AddChild(app.vbBlue);
     //_________________________________________________________ 3. Scene setup
     app.engine.scene[L"mainScene"] = &app.mainScene;
     app.engine.SetCurrentScene(L"mainScene");
     app.mainScene.figure[0].vertexBuffer = &app.vbRed;
     app.mainScene.figure[1].vertexBuffer = &app.vbGreen;
     app.mainScene.figure[2].vertexBuffer = &app.vbBlue;
     //_________________________________________________________ 4. Run the app
     return app.Run(. . .);
}


Problem 2
Create a DirectX application using Wintempla called SunX to test diffuse lighting on objects with textures. For this exercise, we will need a squared image. The program will draw three cubes, starting on the left, the first cube has diffused lighting, the second cube has ambient and diffuse lighting, while the last one has ambient, diffused and specular lighting. After creating the project, add a DirectX object called Cube and a DirectX scene called MainScene.
Cree una aplicación de DirectX usando Wintempla llamada SunX para probar la iluminación difusa en objetos con texturas. Para este ejercicio, nosotros necesitaremos una imagen cuadrada. El programa dibujará tres cubos, empezando en la izquierda, el primer cubo tiene iluminación difusa, el segundo cubo tiene luz ambiental y difusa, mientras que el último tiene iluminación ambiental, difusa y especular. Después de crear el proyecto, agregue un objeto de DirectX llamado Cube y una escena de DirectX llamada MainScene.

SunXRun1

SunXRun2

SunXRun3

SunXRun4

Cube.h
//____________________________________________________________ Cube.h
#pragma once

#define LIGHT_AMBIENT 0
#define LIGHT_DIFFUSE 1
#define LIGHT_SPECULAR 2

class Cube : public DX11::Object3D
{
public:
     float x = 0.0f, y = 0.0f, z = 0.0f;
     float angleY = 0.0f;
     DirectX::XMMATRIX scale = DirectX::XMMatrixScaling(0.6f, 0.6f, 0.6f); //DirectX::XMMatrixIdentity();
     int light = LIGHT_AMBIENT;
     DX11::Texture* texture = nullptr;
     bool OnCreateScene(DX11::Engine& engine);
     . . .
};


Cube.cpp
. . .
void Cube::OnUpdate(DX11::Engine& engine, float sec, float deltaSec)
{
     angleY += (0.5f*deltaSec);
     world = DirectX::XMMatrixRotationY(angleY);
     DirectX::XMMATRIX translation = DirectX::XMMatrixTranslation(x, y, z);
     world = DirectX::XMMatrixMultiply(world, translation);
     world = DirectX::XMMatrixMultiply(scale, world);
     if (angleY > DirectX::XM_2PI) angleY -= DirectX::XM_2PI;
}

void Cube::OnRender3D(DX11::Engine& engine)
{
     if (light == LIGHT_AMBIENT)
     {
          engine.shaderTextuAmbient.Render(engine, world, vertexBuffer->GetIndexCount(), 0, 0, *texture);
     }
     else if (light == LIGHT_DIFFUSE)
     {
          engine.shaderTextuDiffuse.Render(engine, world, vertexBuffer->GetIndexCount(), 0, 0, *texture);
     }
     else // LIGHT_SPECULAR
     {
          engine.shaderTextuSpecular.Render(engine, world, vertexBuffer->GetIndexCount(), 0, 0, *texture);
     }
}
. . .


MainScene.h
//____________________________________________________________ MainScene.h
#pragma once
#include "Cube.h"

class MainScene : public DX11::Scene
{
public:
     Cube cube[3];
     DX11::Texture texture;
     void OnCreateScene(DX11::Engine& engine);
     . . .
};


MainScene.cpp
. . .
void MainScene::OnCreateScene(DX11::Engine& engine)
{
     //_______________________________________ 1. Set back color RGBA
     this->SetBackColor(0.0f, 0.0f, 0.4f, 1.0f);
     //_______________________________________ 2.Set cube position
     cube[0].x = 0.0f;
     cube[1].x = -1.8f;
     cube[2].x = 1.8f;
     //_______________________________________ 3. Set texture
     cube[0].texture = &texture;
     cube[1].texture = &texture;
     cube[2].texture = &texture;
     //_______________________________________ 4. Set light
     cube[0].light = LIGHT_AMBIENT;
     cube[1].light = LIGHT_DIFFUSE;
     cube[2].light = LIGHT_SPECULAR;
     //_______________________________________ 5. Add children
     this->AddChild(cube[0]);
     this->AddChild(cube[1]);
     this->AddChild(cube[2]);
     //_______________________________________ 6. Camera & Light setup (light.ambientColor)
     camera.position.x = 0.0f;
     camera.position.y = 0.0f;
     camera.position.z = -5.0f;
     camera.lookAt.x = 0.0f;
     camera.lookAt.y = 0.0f;
     camera.lookAt.z = 1.0f;
}

void MainScene::OnUpdate(DX11::Engine& engine, float sec, float deltaSec)
{
     //__________________________________________________ 1. Move camera with keyboard
     if (engine.keyboard[VK_UP]) camera.position.y -= deltaSec;
     if (engine.keyboard[VK_DOWN]) camera.position.y += deltaSec;
     if (engine.keyboard[VK_LEFT]) camera.position.x += deltaSec;
     if (engine.keyboard[VK_RIGHT]) camera.position.x -= deltaSec;
     //__________________________________________________ 2. Move camera with mouse wheel
     if (engine.poitingDevice.distanceWheelRotated > 10)
     {
          camera.position.z -= (10.0f*deltaSec);
     }
     else if (engine.poitingDevice.distanceWheelRotated < -10)
     {
          camera.position.z += (10.0f*deltaSec);
     }
     camera.Update();
}
. . .


SunX.h
#pragma once //______________________________________ SunX.h
#include "Resource.h"
#include "MainScene.h"

class SunX : public DX11::Window
{
public:
     MainScene mainScene;
     DX11::TextureNormVertexBuffer vb;
};


SunX.cpp
. . .
int APIENTRY wWinMain(. . .)
{
     SunX app;
     //_________________________________________________________ 1. Load texture
     const wchar_t* error = app.mainScene.texture.CreateData(L"floor.bmp");
     if (error != nullptr)
     {
          ::MessageBox(NULL, error, L"floor.bmp", MB_OK | MB_ICONERROR);
          return 0;
     }
     app.engine.AddChild(app.mainScene.texture);
     //_________________________________________________________ 2. Create vertex buffers
     vector<valarray<Sys::Vertex> > mesh;
     Sys::Tessellator tessellator;
     tessellator.GenerateBox(mesh);
     app.vb.CreateData(mesh, false);
     //_________________________________________________________ 3. Add vertex buffers to the engine
     app.engine.AddChild(app.vb);
     //_________________________________________________________ 4. Set vertex buffers to the 3D objects
     app.mainScene.cube[0].vertexBuffer = &app.vb;
     app.mainScene.cube[1].vertexBuffer = &app.vb;
     app.mainScene.cube[2].vertexBuffer = &app.vb;
     //_________________________________________________________ 5. Scene setup
     app.engine.scene[L"mainScene"] = &app.mainScene;
     app.engine.SetCurrentScene(L"mainScene");
     //_________________________________________________________ 6. Run the app
     return app.Run(. . .);
}


Problem 3
This problem illustrates how to use DirectX to render one rectangular part of the program and interact with Graphical User Interface elements (GUI elements). Create a Dialog application using Wintempla called Area3D. Observe that this is not a DirectX application.
Este problema ilustra cómo usar DirectX para dibujar una área rectangular del programa e interacturar con elementos de Interface Gráfica de Usuario (elementos GUI). Cree una aplicación de Diálogo usando Wintempla llamada Area3D. Observe que esta no es una DirectX application.

Area3DRun1

Area3DRun2

Step A
Copy the files DX11.h and DX11.cpp from a previous DirectX project to the Area3D project folder as shown.
Copie los archivos DX11.h y DX11.cpp desde un los proyectos previos de DirectX a la carpeta del proyecto Area3D cómo se muestra.

Dx11Files

Step B
Open Solution Explorer, select the Area3D project and right click with the mouse to open the context menu as shown Add > Existing Item. . . . Select the files DX11.h and DX11.cpp.

AddExistingItem

SolutionExplorer

Step C
Edit the stdafx.h file as shown.
Edite el archivo stdafx.h como se muestra.

stdafx.h
. . .
#include "Wintempla.h"
#include "WintemplaWin.h"
#include "DX11.h"
using namespace std;
. . .


Step D
From Microsoft Visual Studio menu Tools > Add Wintempla Item. . . > Custom Control . Set the name to RealView. This will create two files: RealView.h and RealView.cpp. Edit these files as shown.
Desde el menú de Microsoft Visual Studio Tools > Add Wintempla Item. . . > Custom Control . Fije el nombre a RealView. Esto creará dos archivos: RealView.h y RealView.cpp. Edite estos archivos cómo se muestra.

RealView.h
//____________________________________________________________ RealView.h
#pragma once
#include "resource.h"
//To create an object of this class, you must insert a Custom Control in the GUI

class RealView: public Win::Window
{
public:
     RealView();
     ~RealView();
     DX11::ScreenDevice screenDevice;
     DX11::ColorShader shaderColor;
     DX11::ColorDiffuseLightShader shaderColorDiffuse;
     DX11::Camera camera;
     DX11::Light light;
     //____________________________________________________ Cube
     DirectX::XMMATRIX world = DirectX::XMMatrixIdentity();
     DX11::ColorNormVertexBuffer vbCube;
     float angleY = 0.0f;
     void Turn(float delta);
     //____________________________________________________ Font
     virtual void SetFont(Win::Gdi::Font& font);
     __declspec( property( put=SetFont) ) Win::Gdi::Font& Font;
     //____________________________________________________ Events
     bool IsEvent(Win::Event& e, int notification);
private:
     const wchar_t * GetClassName(void){return L"RealView";}
     static bool isRegistered;
protected:
     HFONT _hFont;
     //______ Wintempla GUI manager section begin: DO NOT EDIT AFTER THIS LINE
     void Window_Open(Win::Event& e);
     void Window_Paint(Win::Event& e);
     void Window_Size(Win::Event& e);
};


RealView.cpp
#include "stdafx.h"
#include "RealView.h"

bool RealView::isRegistered= false;

RealView::RealView()
{     
     //__________________________________________________________ 1. RegisterClassEx
     if (!this->isRegistered)
     {

          this->RegisterClassEx(
               LoadCursor(NULL, IDC_ARROW), // Cursor: IDC_IBEAM, IDC_WAIT, IDC_CROSS, ...
               (HBRUSH)::GetStockObject(NULL_BRUSH));
          this->isRegistered = true;
     }
     //__________________________________________________________ 2. shader.push_back
     screenDevice.shader.push_back(& shaderColorDiffuse);
     //__________________________________________________________ 3. camera setup
     camera.position.x = 0.0f;
     camera.position.y = 0.0f;
     camera.position.z = -5.0f;
     camera.lookAt.x = 0.0f;
     camera.lookAt.y = 0.0f;
     camera.lookAt.z = 1.0f;
     //__________________________________________________________ 4. Prompt user for screen setup
     DX11::AdapterDlg dlg;
     if (dlg.BeginDialog(NULL) != TRUE) return;
     screenDevice.modeDesc = dlg.modeDescList[dlg.modeIndex];
     screenDevice.adapterIndex = dlg.adapterIndex;
     screenDevice.isFullScreen = false;
}

RealView::~RealView()
{
}

void RealView::Turn(float delta)
{
     angleY += delta;
     world = DirectX::XMMatrixRotationY(angleY);
     ::InvalidateRect(hWnd, NULL, FALSE);
}

void RealView::Window_Open(Win::Event& e)
{
     const wchar_t* error = nullptr;
     //________________________________________________ 1. Create vertex buffer with a cube
     vector<valarray<Sys::Vertex> > mesh;
     Sys::Tessellator tessellator;
     tessellator.GenerateBox(mesh);
     vbCube.CreateData(mesh, DirectX::XMFLOAT4(1.0f, 0.0f, 0.0f, 1.0f), false);
     screenDevice.vertexBuffer.push_back(&vbCube);
     //________________________________________________ 2. Compile shaders
     error = shaderColor.Compile("main", "main");
     if (error != nullptr)
     {
          this->MessageBox(error, L"RealView", MB_OK | MB_ICONERROR);
          return;
     }
     error = shaderColorDiffuse.Compile("main", "main");
     if (error != nullptr)
     {
          this->MessageBox(error, L"RealView", MB_OK | MB_ICONERROR);
          return;
     }
     //________________________________________________ 3. screenDevice.Create
     screenDevice.outputWindow = hWnd;
     error = screenDevice.Create();
     if (error != nullptr)
     {
          this->MessageBox(error, L"RealView", MB_OK | MB_ICONERROR);
     }
}

void RealView::Window_Paint(Win::Event& e)
{
     screenDevice.Clear(0.0f, 0.0f, 0.2f, 1.0f);
     camera.Update();
     vbCube.Render(screenDevice.deviceContext);
     shaderColorDiffuse.Render(screenDevice.deviceContext, vbCube.GetIndexCount(), 0, 0, world, camera, light);

     const HRESULT hr = screenDevice.swapChain->Present(1, 0);
     if (FAILED(hr))
     {
          const wchar_t* error = screenDevice.Create();
          if (error != nullptr)
          {
               this->MessageBox(error, L"RealView", MB_OK | MB_ICONERROR);
          }
     }
     ::ValidateRect(hWnd, NULL);
}

void RealView::Window_Size(Win::Event& e)
{
     const float w = (float)LOWORD(e.lParam);
     const float h = (float)HIWORD(e.lParam);
     this->screenDevice.Resize(w, h);
     this->camera.SetViewInfo(w, h, false);
}

void RealView::SetFont(Win::Gdi::Font& font)
{
     this->_hFont = font.GetHFONT();
     ::InvalidateRect(hWnd, NULL, FALSE);
}

bool RealView::IsEvent(Win::Event& e, int notification)
{
//     if (e.uMsg == WM_NOTIFY)
//     {
//          NMHDR* pNMHDR= (LPNMHDR)e.lParam;
//          if (pNMHDR->hwndFrom!=this->GetHWND()) return false;
//          if (notification == WIN_ALL_EVENTS)
//          {
//               // Your code here
//               return true;
//          }
//          if (pNMHDR->code!=notification) return false;
//          return true;
//     }
//
     if (e.uMsg!=WM_COMMAND) return false;
     const int id = LOWORD(e.wParam);
     const int notificationd = HIWORD(e.wParam);
     if (id != this->id) return false;
     if (notificationd!=notification) return false;
     return true;
}


Step E
Use Wintempla to edit the GUI as shown. On Wintempla toolbar click on Show All Controls in Toolbox, then insert a Custom Control and two buttons as shown. After inserting the Custom Control, set the Class Name to RealView as shown.
Use Wintempla para editar la GUI como se muestra. En la barra de herramientas de Wintempla haga clic en Show All Controls in Toolbox, entonces inserte un Custom Control y dos botones como se muestra. Después de insertar el Custom Control, fije el Class Name a RealView como se muestra.

Area3DGUI

Classname

Step F
Edit the Area3D.cpp file as shown.
Edite el archivo Area3D.cpp cómo se muestra.

Area3D.cpp
#include "stdafx.h" //________________________________________ Area3D.cpp
#include "Area3D.h"

int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE , LPTSTR cmdLine, int cmdShow){
     Area3D app;
     return app.BeginDialog(IDI_Area3D, hInstance);
}

void Area3D::Window_Open(Win::Event& e)
{
}

void Area3D::btLeft_Click(Win::Event& e)
{
     customControlRV.Turn(0.1f);
}

void Area3D::btRight_Click(Win::Event& e)
{
     customControlRV.Turn(-0.1f);
}


© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home