2078 3

CSC214 ยท 2078 ยท 10 marks

List some significance of virtual reality. Differentiate between virtual reality and augmented reality with example. Demonstrate how a polygon can be created using OpenGL.

List some significance of virtual reality. Differentiate between virtual reality and augmented reality with example. Demonstrate how a polygon can be created using OpenGL.[10]

Computer GraphicsChapter 9: Introduction to Virtual RealityApplication of VR

Quick answer

Virtual Reality (VR) is an artificial environment created with software and presented to the user in such a way that the user suspends belief and accepts it as a real environment. It uses computer technology to create a simulated, interactive 3D environment.

Virtual Reality: Significance, VR vs AR, and Polygon Creation in OpenGL


1. Significance of Virtual Reality (4 marks)

The key significances of Virtual Reality are:

  1. Education and Training: VR provides a safe and controlled simulated environment for training purposes. Medical students can practice surgeries, pilots can practice flying, and soldiers can practice combat scenarios without real-world risk.

  2. Entertainment and Gaming: VR creates fully immersive gaming and entertainment experiences where users feel physically present inside the virtual world, greatly enhancing user experience.

  3. Healthcare and Therapy: VR is used in pain management, rehabilitation, treatment of phobias (exposure therapy), and post-traumatic stress disorder (PTSD) treatment by simulating controlled therapeutic environments.

  4. Architecture and Design: Architects and designers use VR to create virtual walkthroughs of buildings and structures before they are physically built, helping clients visualize the final product.

  5. Scientific Visualization: Scientists use VR to visualize complex data, molecular structures, astronomical phenomena, and simulations that are otherwise impossible to observe directly.

  6. Military and Defense: VR is used for battlefield simulations, vehicle operation training, and strategic planning without putting soldiers in actual danger.

  7. Natural Interaction: VR supports natural input devices such as joysticks, tracking balls, data gloves, and motion platforms, allowing users to interact with the virtual environment in an intuitive and immersive manner.


2. Difference Between Virtual Reality (VR) and Augmented Reality (AR) (3 marks)

Augmented Reality (AR) is the technology that expands our physical world by adding layers of digital information (such as sound, images, and text) on top of the real world we see.

BasisVirtual Reality (VR)Augmented Reality (AR)
DefinitionCreates an entirely virtual world using softwareA mix of the real world and the virtual world
Real WorldCompletely replaces the real world with a simulated environmentSuperimposes digital information on the real world
DistinctionIt is hard to differentiate between what is real and what is not realUsers can clearly distinguish between the real and virtual elements
Hardware UsedGenerally achieved by wearing a helmet or goggles having VR technologyAchieved by holding a smartphone or using AR glasses in front of us
Immersion LevelFully immersive; user is isolated from the real worldPartially immersive; user remains aware of the real world
TypesSingle type of fully simulated environmentMarkerless AR, Marker-based AR, Projection-based AR, Superimposition-based AR

Examples:

  • VR Example: A user wearing an Oculus Rift headset is completely immersed in a virtual game world such as a battlefield or a fantasy land. The user sees nothing of the real world.

  • AR Example: Using the smartphone app Pokemon Go, virtual Pokemon characters are superimposed on the real-world camera view. The user sees both the real street and the virtual Pokemon at the same time.


3. Creating a Polygon Using OpenGL (3 marks)

OpenGL (Open Graphics Library) is a general-purpose graphics programming package that contains graphics functions used with high-level programming languages like C, C++, Java, etc.

In OpenGL, a polygon can be created using the glBegin() and glEnd() functions along with glVertex2f() or glVertex3f() to specify the vertices of the polygon.

Key OpenGL Functions Used:

  • glBegin(GL_POLYGON) - Starts the definition of a polygon
  • glVertex2f(x, y) - Specifies a 2D vertex of the polygon
  • glEnd() - Ends the definition of the polygon
  • glColor3f(r, g, b) - Sets the drawing color
  • glClear(GL_COLOR_BUFFER_BIT) - Clears the screen
  • glFlush() - Forces execution of OpenGL commands

Complete Program to Draw a Triangle (3-sided Polygon):

#include <GL/glut.h>

void display() {
    // Clear the screen with background color
    glClear(GL_COLOR_BUFFER_BIT);

    // Set the drawing color to red (R=1, G=0, B=0)
    glColor3f(1.0, 0.0, 0.0);

    // Begin drawing a polygon (triangle)
    glBegin(GL_POLYGON);
        glVertex2f(0.0, 0.5);    // Top vertex
        glVertex2f(-0.5, -0.5);  // Bottom-left vertex
        glVertex2f(0.5, -0.5);   // Bottom-right vertex
    glEnd();

    // Flush the drawing to the screen
    glFlush();
}

int main(int argc, char** argv) {
    // Initialize GLUT
    glutInit(&argc, argv);

    // Set display mode
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

    // Set window size
    glutInitWindowSize(500, 500);

    // Set window position
    glutInitWindowPosition(100, 100);

    // Create the window with a title
    glutCreateWindow("Polygon using OpenGL");

    // Set background color to white
    glClearColor(1.0, 1.0, 1.0, 0.0);

    // Register display callback function
    glutDisplayFunc(display);

    // Enter the GLUT event loop
    glutMainLoop();

    return 0;
}

Explanation of Steps:

StepFunctionPurpose
1glutInit()Initializes the GLUT library
2glutInitDisplayMode()Sets single buffer and RGB color mode
3glutInitWindowSize()Sets the width and height of the display window
4glutInitWindowPosition()Fixes the position of the window on the screen
5glutCreateWindow()Creates the window and gives it a title
6glClearColor()Sets the background colour of the window
7glutDisplayFunc()Registers the callback function that draws the scene
8glutMainLoop()Enters the event loop so the window stays on screen

Running this program draws a solid red triangle on a white background, which is the simplest polygon OpenGL can render. Adding further glVertex2f() calls between glBegin(GL_POLYGON) and glEnd() produces a polygon with as many sides as vertices supplied, and the vertices must be given in order around the boundary so that the polygon stays simple and convex.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.