SlideShare a Scribd company logo
1 of 43
Download to read offline
Mohammad Shaker
mohammadshaker.com
@ZGTRShaker
2015
OpenGL Graphics
L07-SKYBOX&TERRAIN
How to create the Sky?
Skydome and Skybox
Skydome
SkyBox
SkyBox
Just 6 textures!
See the code
SkyBox
SkyBox
SkyBox
SkyBox
Now, How to create the ground?!
Terrain
Terrain
Grid
Terrain
Grid Height Map
+
Terrain
Grid
=
Height Map
+
Terrain
+
Colored Terrain
Terrain
Texture 24 bits
+
Colored Terrain
+
Terrain
=
Texture 24 bits
+
3D TerrainColored Terrain
+
Planetside’s
Terragen
Planetside’s Terragen
Terrain’s Height Map Representation
Terrain’s Height Map Representation
Terrain, The Code
Terrain
• #include “texture.h”
• #include “heightMap.h”
• Define
int terraintexture ; // index to terrain texture
GLubyte * HeightData ; // vector (saving heights)
int TerrainSize = 512; // width = height = 512
float step = 1/512.0; // step for texture
• InitGL()
terraintexture = LoadTexture("imagesterrain texture.bmp");
HeightData = new GLubyte(TerrainSize*TerrainSize);
HeightData = LoadHeightMap("imagesterrain height.bmp");
Terrain – Draw Algorithm
initTerrainPositionX = TerrainSize/2.0f; initTerrainPositionZ = TerrainSize/2.0f; initTerrainPositionY = 0;
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,terraintexture);
glScalef(scaleX,scaleY,scaleZ);
glTranslatef(-initTerrainPositionX, initTerrainPositionY, -initTerrainPositionZ);
for (int i = 3 ; i<TerrainSize-3 ; i++)
{
glBegin(GL_TRIANGLE_STRIP);
for (int j = 3 ; j < TerrainSize -3; j++)
{
glTexCoord2f(j*step,i*step);
glVertex3f(i, GetValue(i,j), j);
glTexCoord2f((j+1)*step,i*step);
glVertex3f(i, GetValue(i,j+1), j+1);
glTexCoord2f(j*step,(i+1)*step);
glVertex3f(i+1, GetValue(i+1,j), j);
glTexCoord2f((j+1)*step,(i+1)*step);
glVertex3f(i+1, GetValue(i+1,j+1), j+1);
}
glEnd();
}
glDisable(GL_TEXTURE_2D);
glPopMatrix();
Terrain – Draw Algorithm
initTerrainPositionX = TerrainSize/2.0f; initTerrainPositionZ = TerrainSize/2.0f; initTerrainPositionY = 0;
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,terraintexture);
glScalef(scaleX,scaleY,scaleZ);
glTranslatef(-initTerrainPositionX, initTerrainPositionY, -initTerrainPositionZ);
for (int i = 3 ; i<TerrainSize-3 ; i++)
{
glBegin(GL_TRIANGLE_STRIP);
for (int j = 3 ; j < TerrainSize -3; j++)
{
glTexCoord2f(j*step,i*step);
glVertex3f(i, GetValue(i,j), j);
glTexCoord2f((j+1)*step,i*step);
glVertex3f(i, GetValue(i,j+1), j+1);
glTexCoord2f(j*step,(i+1)*step);
glVertex3f(i+1, GetValue(i+1,j), j);
glTexCoord2f((j+1)*step,(i+1)*step);
glVertex3f(i+1, GetValue(i+1,j+1), j+1);
}
glEnd();
}
glDisable(GL_TEXTURE_2D);
glPopMatrix();
Scale the terrain
Terrain – Draw Algorithm
initTerrainPositionX = TerrainSize/2.0f; initTerrainPositionZ = TerrainSize/2.0f; initTerrainPositionY = 0;
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,terraintexture);
glScalef(scaleX,scaleY,scaleZ);
glTranslatef(-initTerrainPositionX, initTerrainPositionY, -initTerrainPositionZ);
for (int i = 3 ; i<TerrainSize-3 ; i++)
{
glBegin(GL_TRIANGLE_STRIP);
for (int j = 3 ; j < TerrainSize -3; j++)
{
glTexCoord2f(j*step,i*step);
glVertex3f(i, GetValue(i,j), j);
glTexCoord2f((j+1)*step,i*step);
glVertex3f(i, GetValue(i,j+1), j+1);
glTexCoord2f(j*step,(i+1)*step);
glVertex3f(i+1, GetValue(i+1,j), j);
glTexCoord2f((j+1)*step,(i+1)*step);
glVertex3f(i+1, GetValue(i+1,j+1), j+1);
}
glEnd();
}
glDisable(GL_TEXTURE_2D);
glPopMatrix();
Translate the terrain
Terrain – Draw Algorithm
initTerrainPositionX = TerrainSize/2.0f; initTerrainPositionZ = TerrainSize/2.0f; initTerrainPositionY = 0;
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,terraintexture);
glScalef(scaleX,scaleY,scaleZ);
glTranslatef(-initTerrainPositionX, initTerrainPositionY, -initTerrainPositionZ);
for (int i = 3 ; i<TerrainSize-3 ; i++)
{
glBegin(GL_TRIANGLE_STRIP);
for (int j = 3 ; j < TerrainSize -3; j++)
{
glTexCoord2f(j*step,i*step);
glVertex3f(i, GetValue(i,j), j);
glTexCoord2f((j+1)*step,i*step);
glVertex3f(i, GetValue(i,j+1), j+1);
glTexCoord2f(j*step,(i+1)*step);
glVertex3f(i+1, GetValue(i+1,j), j);
glTexCoord2f((j+1)*step,(i+1)*step);
glVertex3f(i+1, GetValue(i+1,j+1), j+1);
}
glEnd();
}
glDisable(GL_TEXTURE_2D);
glPopMatrix();
Drawing the terrain primitives
Querying Height
Terrain – Querying Height
MyCamera.Position.y = (float)(GetValue(
(int)((MyCamera.Position.x + initTerrainPositionX) * scaleX),
(int)((MyCamera.Position.z + initTerrainPositionZ) * scaleZ)
))
*scaleY
+15;
Terrain – Querying Height
MyCamera.Position.y = (float)(GetValue(
(int)((MyCamera.Position.x + initTerrainPositionX) * scaleX),
(int)((MyCamera.Position.z + initTerrainPositionZ) * scaleZ)
))
*scaleY
+15;
Getting the correspondent map height
at the camera’s current position
Terrain – Querying Height
MyCamera.Position.y = (float)(GetValue(
(int)((MyCamera.Position.x + initTerrainPositionX) * scaleX),
(int)((MyCamera.Position.z + initTerrainPositionZ) * scaleZ)
))
*scaleY
+15;
Compensate for any translation on X
and/or Z axis
Terrain – Querying Height
MyCamera.Position.y = (float)(GetValue(
(int)((MyCamera.Position.x + initTerrainPositionX) * scaleX),
(int)((MyCamera.Position.z + initTerrainPositionZ) * scaleZ)
))
*scaleY
+15;
Scale it by how much you scaled the
terrain on X and Z axis
Terrain – Querying Height
MyCamera.Position.y = (float)(GetValue(
(int)((MyCamera.Position.x + initTerrainPositionX) * scaleX),
(int)((MyCamera.Position.z + initTerrainPositionZ) * scaleZ)
))
*scaleY
+15;
And scale the y value in the height map
by how much the terrain is Y scaled
Terrain – Querying Height
MyCamera.Position.y = (float)(GetValue(
(int)((MyCamera.Position.x + initTerrainPositionX) * scaleX),
(int)((MyCamera.Position.z + initTerrainPositionZ) * scaleZ)
))
*scaleY
+15; And hover above the position a bit
Advanced Techniques
Quad Tree for Fast Searching in Big Worlds
Multitexturing
• Just another custom shader!
Detailing
Multitexturing
Ray and Terrain Collision – Binary Tree Search
Using Custom Shaders
OpenGL L07-Skybox and Terrian

More Related Content

What's hot

Introduction to open gl in android droidcon - slides
Introduction to open gl in android   droidcon - slidesIntroduction to open gl in android   droidcon - slides
Introduction to open gl in android droidcon - slides
tamillarasan
 
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis GraphRedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
Redis Labs
 
Building Efficient and Highly Run-Time Adaptable Virtual Machines
Building Efficient and Highly Run-Time Adaptable Virtual MachinesBuilding Efficient and Highly Run-Time Adaptable Virtual Machines
Building Efficient and Highly Run-Time Adaptable Virtual Machines
Guido Chari
 

What's hot (20)

Introduction to open gl in android droidcon - slides
Introduction to open gl in android   droidcon - slidesIntroduction to open gl in android   droidcon - slides
Introduction to open gl in android droidcon - slides
 
Opengl presentation
Opengl presentationOpengl presentation
Opengl presentation
 
OpenGL Introduction
OpenGL IntroductionOpenGL Introduction
OpenGL Introduction
 
Graphics in C++
Graphics in C++Graphics in C++
Graphics in C++
 
OpenGL L02-Transformations
OpenGL L02-TransformationsOpenGL L02-Transformations
OpenGL L02-Transformations
 
Grafika komputer 2
Grafika komputer 2Grafika komputer 2
Grafika komputer 2
 
Graphics Programming in C
Graphics Programming in CGraphics Programming in C
Graphics Programming in C
 
Games 3 dl4-example
Games 3 dl4-exampleGames 3 dl4-example
Games 3 dl4-example
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5
 
Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)Tutorial Open GL (Listing Code)
Tutorial Open GL (Listing Code)
 
GLSL
GLSLGLSL
GLSL
 
How the Go runtime implement maps efficiently
How the Go runtime implement maps efficientlyHow the Go runtime implement maps efficiently
How the Go runtime implement maps efficiently
 
OpenGL Introduction
OpenGL IntroductionOpenGL Introduction
OpenGL Introduction
 
Computer graphics practical(jainam)
Computer graphics practical(jainam)Computer graphics practical(jainam)
Computer graphics practical(jainam)
 
Computer Graphics Project on Sinking Ship using OpenGL
Computer Graphics Project on Sinking Ship using OpenGLComputer Graphics Project on Sinking Ship using OpenGL
Computer Graphics Project on Sinking Ship using OpenGL
 
Unity programming 1
Unity programming 1Unity programming 1
Unity programming 1
 
[C++ GUI Programming with Qt4] chap8
[C++ GUI Programming with Qt4] chap8[C++ GUI Programming with Qt4] chap8
[C++ GUI Programming with Qt4] chap8
 
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis GraphRedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
RedisConf18 - Lower Latency Graph Queries in Cypher with Redis Graph
 
OpenGL L01-Primitives
OpenGL L01-PrimitivesOpenGL L01-Primitives
OpenGL L01-Primitives
 
Building Efficient and Highly Run-Time Adaptable Virtual Machines
Building Efficient and Highly Run-Time Adaptable Virtual MachinesBuilding Efficient and Highly Run-Time Adaptable Virtual Machines
Building Efficient and Highly Run-Time Adaptable Virtual Machines
 

Viewers also liked

lecture3 color representation in computer graphics(Computer graphics tutorials)
lecture3 color representation in computer graphics(Computer graphics tutorials)lecture3 color representation in computer graphics(Computer graphics tutorials)
lecture3 color representation in computer graphics(Computer graphics tutorials)
Daroko blog(www.professionalbloggertricks.com)
 
Lecture 6 introduction to open gl and glut
Lecture 6   introduction to open gl and glutLecture 6   introduction to open gl and glut
Lecture 6 introduction to open gl and glut
simpleok
 

Viewers also liked (13)

NVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityNVIDIA's OpenGL Functionality
NVIDIA's OpenGL Functionality
 
Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGL
 
OpenGL Basics
OpenGL BasicsOpenGL Basics
OpenGL Basics
 
Open GL Tutorial06
Open GL Tutorial06Open GL Tutorial06
Open GL Tutorial06
 
OpenGL L04-Lighting
OpenGL L04-LightingOpenGL L04-Lighting
OpenGL L04-Lighting
 
Open gles
Open glesOpen gles
Open gles
 
COMPUTER GRAPHICS DAY1
COMPUTER GRAPHICS DAY1COMPUTER GRAPHICS DAY1
COMPUTER GRAPHICS DAY1
 
lecture3 color representation in computer graphics(Computer graphics tutorials)
lecture3 color representation in computer graphics(Computer graphics tutorials)lecture3 color representation in computer graphics(Computer graphics tutorials)
lecture3 color representation in computer graphics(Computer graphics tutorials)
 
Lecture 6 introduction to open gl and glut
Lecture 6   introduction to open gl and glutLecture 6   introduction to open gl and glut
Lecture 6 introduction to open gl and glut
 
Open gl
Open glOpen gl
Open gl
 
Global Power Systems Pvt. Ltd., Nagpur, Generators Set & Controller
Global Power Systems Pvt. Ltd., Nagpur, Generators Set & ControllerGlobal Power Systems Pvt. Ltd., Nagpur, Generators Set & Controller
Global Power Systems Pvt. Ltd., Nagpur, Generators Set & Controller
 
Eternal Engineering Equipment (p.) Ltd., Pune, Vibration Laboratory
 Eternal Engineering Equipment (p.) Ltd., Pune, Vibration Laboratory Eternal Engineering Equipment (p.) Ltd., Pune, Vibration Laboratory
Eternal Engineering Equipment (p.) Ltd., Pune, Vibration Laboratory
 
Machinery industrial parts
Machinery industrial partsMachinery industrial parts
Machinery industrial parts
 

Similar to OpenGL L07-Skybox and Terrian

Mashup caravan android-talks
Mashup caravan android-talksMashup caravan android-talks
Mashup caravan android-talks
honjo2
 
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdfimport java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
anyacarpets
 
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docxCOMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
TashiBhutia12
 

Similar to OpenGL L07-Skybox and Terrian (20)

Mashup caravan android-talks
Mashup caravan android-talksMashup caravan android-talks
Mashup caravan android-talks
 
libGDX: Tiled Maps
libGDX: Tiled MapslibGDX: Tiled Maps
libGDX: Tiled Maps
 
PART 4: GEOGRAPHIC SCRIPTING
PART 4: GEOGRAPHIC SCRIPTINGPART 4: GEOGRAPHIC SCRIPTING
PART 4: GEOGRAPHIC SCRIPTING
 
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdfimport java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
import java.awt.;import java.awt.event.MouseAdaptor;import java.pdf
 
Creating an Uber Clone - Part VIII - Transcript.pdf
Creating an Uber Clone - Part VIII - Transcript.pdfCreating an Uber Clone - Part VIII - Transcript.pdf
Creating an Uber Clone - Part VIII - Transcript.pdf
 
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docxCOMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
COMPAPPABCA49085rFunrAP__Practical Number 9 & 10.docx
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision Detection
 
Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2ME
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3D
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGL
 
201707 SER332 Lecture 21
201707 SER332 Lecture 21   201707 SER332 Lecture 21
201707 SER332 Lecture 21
 
Maps
MapsMaps
Maps
 
Geohex at Off4g2009
Geohex at Off4g2009Geohex at Off4g2009
Geohex at Off4g2009
 
Developing Applications with Microsoft Virtual Earth
Developing Applications with Microsoft Virtual EarthDeveloping Applications with Microsoft Virtual Earth
Developing Applications with Microsoft Virtual Earth
 
Opengl texturing
Opengl texturingOpengl texturing
Opengl texturing
 
Geo Spatial Plot using R
Geo Spatial Plot using R Geo Spatial Plot using R
Geo Spatial Plot using R
 
Creating an Uber Clone - Part XXII - Transcript.pdf
Creating an Uber Clone - Part XXII - Transcript.pdfCreating an Uber Clone - Part XXII - Transcript.pdf
Creating an Uber Clone - Part XXII - Transcript.pdf
 
Elastic response pseudo spectrum in c programming
Elastic response pseudo spectrum in c programmingElastic response pseudo spectrum in c programming
Elastic response pseudo spectrum in c programming
 
Creating an Uber Clone - Part XXI - Transcript.pdf
Creating an Uber Clone - Part XXI - Transcript.pdfCreating an Uber Clone - Part XXI - Transcript.pdf
Creating an Uber Clone - Part XXI - Transcript.pdf
 
Trident International Graphics Workshop 2014 5/5
Trident International Graphics Workshop 2014 5/5Trident International Graphics Workshop 2014 5/5
Trident International Graphics Workshop 2014 5/5
 

More from Mohammad Shaker

More from Mohammad Shaker (20)

12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate
 
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
 
Interaction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyInteraction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with Psychology
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love -  Passioneers Event 2015Short, Matters, Love -  Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game Development
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesAndroid L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and Wearables
 
Interaction Design L03 - Color
Interaction Design L03 - ColorInteraction Design L03 - Color
Interaction Design L03 - Color
 
Interaction Design L05 - Typography
Interaction Design L05 - TypographyInteraction Design L05 - Typography
Interaction Design L05 - Typography
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingInteraction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and Coupling
 
Android L05 - Storage
Android L05 - StorageAndroid L05 - Storage
Android L05 - Storage
 
Android L04 - Notifications and Threading
Android L04 - Notifications and ThreadingAndroid L04 - Notifications and Threading
Android L04 - Notifications and Threading
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOS
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile Constraints
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsInteraction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and Grids
 
Android L10 - Stores and Gaming
Android L10 - Stores and GamingAndroid L10 - Stores and Gaming
Android L10 - Stores and Gaming
 
Android L06 - Cloud / Parse
Android L06 - Cloud / ParseAndroid L06 - Cloud / Parse
Android L06 - Cloud / Parse
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesAndroid L08 - Google Maps and Utilities
Android L08 - Google Maps and Utilities
 
Android L03 - Styles and Themes
Android L03 - Styles and Themes Android L03 - Styles and Themes
Android L03 - Styles and Themes
 
Android L02 - Activities and Adapters
Android L02 - Activities and AdaptersAndroid L02 - Activities and Adapters
Android L02 - Activities and Adapters
 
Android L01 - Warm Up
Android L01 - Warm UpAndroid L01 - Warm Up
Android L01 - Warm Up
 

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 

OpenGL L07-Skybox and Terrian

  • 2. How to create the Sky?
  • 11. Now, How to create the ground?!
  • 18. Terrain = Texture 24 bits + 3D TerrainColored Terrain +
  • 21. Terrain’s Height Map Representation
  • 22. Terrain’s Height Map Representation
  • 24. Terrain • #include “texture.h” • #include “heightMap.h” • Define int terraintexture ; // index to terrain texture GLubyte * HeightData ; // vector (saving heights) int TerrainSize = 512; // width = height = 512 float step = 1/512.0; // step for texture • InitGL() terraintexture = LoadTexture("imagesterrain texture.bmp"); HeightData = new GLubyte(TerrainSize*TerrainSize); HeightData = LoadHeightMap("imagesterrain height.bmp");
  • 25. Terrain – Draw Algorithm initTerrainPositionX = TerrainSize/2.0f; initTerrainPositionZ = TerrainSize/2.0f; initTerrainPositionY = 0; glPushMatrix(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,terraintexture); glScalef(scaleX,scaleY,scaleZ); glTranslatef(-initTerrainPositionX, initTerrainPositionY, -initTerrainPositionZ); for (int i = 3 ; i<TerrainSize-3 ; i++) { glBegin(GL_TRIANGLE_STRIP); for (int j = 3 ; j < TerrainSize -3; j++) { glTexCoord2f(j*step,i*step); glVertex3f(i, GetValue(i,j), j); glTexCoord2f((j+1)*step,i*step); glVertex3f(i, GetValue(i,j+1), j+1); glTexCoord2f(j*step,(i+1)*step); glVertex3f(i+1, GetValue(i+1,j), j); glTexCoord2f((j+1)*step,(i+1)*step); glVertex3f(i+1, GetValue(i+1,j+1), j+1); } glEnd(); } glDisable(GL_TEXTURE_2D); glPopMatrix();
  • 26. Terrain – Draw Algorithm initTerrainPositionX = TerrainSize/2.0f; initTerrainPositionZ = TerrainSize/2.0f; initTerrainPositionY = 0; glPushMatrix(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,terraintexture); glScalef(scaleX,scaleY,scaleZ); glTranslatef(-initTerrainPositionX, initTerrainPositionY, -initTerrainPositionZ); for (int i = 3 ; i<TerrainSize-3 ; i++) { glBegin(GL_TRIANGLE_STRIP); for (int j = 3 ; j < TerrainSize -3; j++) { glTexCoord2f(j*step,i*step); glVertex3f(i, GetValue(i,j), j); glTexCoord2f((j+1)*step,i*step); glVertex3f(i, GetValue(i,j+1), j+1); glTexCoord2f(j*step,(i+1)*step); glVertex3f(i+1, GetValue(i+1,j), j); glTexCoord2f((j+1)*step,(i+1)*step); glVertex3f(i+1, GetValue(i+1,j+1), j+1); } glEnd(); } glDisable(GL_TEXTURE_2D); glPopMatrix(); Scale the terrain
  • 27. Terrain – Draw Algorithm initTerrainPositionX = TerrainSize/2.0f; initTerrainPositionZ = TerrainSize/2.0f; initTerrainPositionY = 0; glPushMatrix(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,terraintexture); glScalef(scaleX,scaleY,scaleZ); glTranslatef(-initTerrainPositionX, initTerrainPositionY, -initTerrainPositionZ); for (int i = 3 ; i<TerrainSize-3 ; i++) { glBegin(GL_TRIANGLE_STRIP); for (int j = 3 ; j < TerrainSize -3; j++) { glTexCoord2f(j*step,i*step); glVertex3f(i, GetValue(i,j), j); glTexCoord2f((j+1)*step,i*step); glVertex3f(i, GetValue(i,j+1), j+1); glTexCoord2f(j*step,(i+1)*step); glVertex3f(i+1, GetValue(i+1,j), j); glTexCoord2f((j+1)*step,(i+1)*step); glVertex3f(i+1, GetValue(i+1,j+1), j+1); } glEnd(); } glDisable(GL_TEXTURE_2D); glPopMatrix(); Translate the terrain
  • 28. Terrain – Draw Algorithm initTerrainPositionX = TerrainSize/2.0f; initTerrainPositionZ = TerrainSize/2.0f; initTerrainPositionY = 0; glPushMatrix(); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D,terraintexture); glScalef(scaleX,scaleY,scaleZ); glTranslatef(-initTerrainPositionX, initTerrainPositionY, -initTerrainPositionZ); for (int i = 3 ; i<TerrainSize-3 ; i++) { glBegin(GL_TRIANGLE_STRIP); for (int j = 3 ; j < TerrainSize -3; j++) { glTexCoord2f(j*step,i*step); glVertex3f(i, GetValue(i,j), j); glTexCoord2f((j+1)*step,i*step); glVertex3f(i, GetValue(i,j+1), j+1); glTexCoord2f(j*step,(i+1)*step); glVertex3f(i+1, GetValue(i+1,j), j); glTexCoord2f((j+1)*step,(i+1)*step); glVertex3f(i+1, GetValue(i+1,j+1), j+1); } glEnd(); } glDisable(GL_TEXTURE_2D); glPopMatrix(); Drawing the terrain primitives
  • 30. Terrain – Querying Height MyCamera.Position.y = (float)(GetValue( (int)((MyCamera.Position.x + initTerrainPositionX) * scaleX), (int)((MyCamera.Position.z + initTerrainPositionZ) * scaleZ) )) *scaleY +15;
  • 31. Terrain – Querying Height MyCamera.Position.y = (float)(GetValue( (int)((MyCamera.Position.x + initTerrainPositionX) * scaleX), (int)((MyCamera.Position.z + initTerrainPositionZ) * scaleZ) )) *scaleY +15; Getting the correspondent map height at the camera’s current position
  • 32. Terrain – Querying Height MyCamera.Position.y = (float)(GetValue( (int)((MyCamera.Position.x + initTerrainPositionX) * scaleX), (int)((MyCamera.Position.z + initTerrainPositionZ) * scaleZ) )) *scaleY +15; Compensate for any translation on X and/or Z axis
  • 33. Terrain – Querying Height MyCamera.Position.y = (float)(GetValue( (int)((MyCamera.Position.x + initTerrainPositionX) * scaleX), (int)((MyCamera.Position.z + initTerrainPositionZ) * scaleZ) )) *scaleY +15; Scale it by how much you scaled the terrain on X and Z axis
  • 34. Terrain – Querying Height MyCamera.Position.y = (float)(GetValue( (int)((MyCamera.Position.x + initTerrainPositionX) * scaleX), (int)((MyCamera.Position.z + initTerrainPositionZ) * scaleZ) )) *scaleY +15; And scale the y value in the height map by how much the terrain is Y scaled
  • 35. Terrain – Querying Height MyCamera.Position.y = (float)(GetValue( (int)((MyCamera.Position.x + initTerrainPositionX) * scaleX), (int)((MyCamera.Position.z + initTerrainPositionZ) * scaleZ) )) *scaleY +15; And hover above the position a bit
  • 37. Quad Tree for Fast Searching in Big Worlds
  • 41. Ray and Terrain Collision – Binary Tree Search