Project Report Graphics
Project Report Graphics
REPORT
SUBMITTED BY
NECHIKETH SURENDRAN
1860427
&
NIRMAL RAJESH
1860434
____________________________________________________________________________________
INTRODUCTION
The development of technology has increased very rapidly and can be found in almost all
areas of human life, author can find one of them in the field of education. Nowadays,
education learning is using technology in order to perform the delivery of material will
become more interesting and easy memorable. The use of technology in education can be
implemented with a visualization on a subject of study. The study of the solar system for
example, by using the visualization of objects in the solar system would facilitate teachers
for the delivery of content. Visualization of the solar system is modified in graphic or animation
to display a collection of celestial objects that consist a large star called the sun, and all objects
that are bound by the force of gravity. The objects are eight planets that make a
revolution or rotation of the sun and remain in orbit respectively.
THEORETICAL BACKGROUND
Computer Graphics
Computer graphics is concerned with all aspects of producing pictures or images using a
computer (Angel, 2012). Computer graphics is the process of transforming a 3D model of the
object in the form of geometric shapes, position, color, texture, and lighting into 2D images.
OpenGL
OpenGL is a computer graphics rendering API or we can say that OpenGL is a library for doing
computer graphics. OpenGL is designed as a streamlined, hardware-independent interface
to be implemented on many different hardware platforms. OpenGL can used to create an
interactive applications that render high-quality color images composed of 3D geometric
objects and image
____________________________________________________________________________________
3. change the status of OpenGL projection mode with command glMatrixMode
(GL_MODELVIEW).
Material/Texture
Material of the solar system based on discussion as needed for design, there are:
1. The composition of the solar system Displays information about the sun and the order of
the planets and their orbital trajectory.
2. Various planets Displays the names of the planets in order.
3. The size of the planet Displaying diameter comparison by the actual size of the planet and
visualization.
4. Distance planet to the sun Displaying diameter comparison by the actual distance of the
planet and visualization.
5. The revolution speed of each planet Revolution speed comparison by the actual speed of
the planet and the visualization
____________________________________________________________________________________
In this visualization, user can interacts with the application to perform transformation
against planets. Users can do the translation and rotation against 3d planets, and can also
plays music to accompanying the visualization of the solar system. User can interact with
the application by keyboard function as follows:
SIDE ARROW: translate to left
SIDE ARROW : translate to right
UP ARROW : translate up
DOWN ARROW : translate down
SOURCE CODE
MAIN
package simulator;
import javax.swing.*;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLProfile;
import simulator.camera.Camera;
import java.awt.*;
frame.setSize(frame.getContentPane().getPreferredSize());
frame.setResizable(true);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setVisible(true);
camera.requestFocus();
}
}
PLANET
____________________________________________________________________________________
package simulator;
import com.jogamp.opengl.*;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.glu.GLUquadric;
import com.jogamp.opengl.util.FPSAnimator;
import com.jogamp.opengl.util.texture.Texture;
import simulator.texture.TextureHandler;
import javax.swing.*;
this.speed = speed;
this.distance = distance;
this.radius = radius;
}
gl.glPushMatrix();
angle = (angle + speed) % 360f;
final float x = (float) Math.sin(Math.toRadians(angle)) * distance;
final float y = (float) Math.cos(Math.toRadians(angle)) * distance;
final float z = 0;
gl.glTranslatef(x, y, z);
draw();
gl.glPopMatrix();
____________________________________________________________________________________
// Set material properties.
float[] rgba = { 1f, 1f, 1f };
gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT, rgba, 0);
gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR, rgba, 0);
gl.glMaterialf(GL2.GL_FRONT, GL2.GL_SHININESS, 0.6f);
// Apply texture.
planetTexture.enable(gl);
planetTexture.bind(gl);
gl.glPushMatrix();
gl.glRotatef(rotationAngle, 0.2f, 0.1f, 0);
gl.glPopMatrix();
}
SUN
package simulator;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.glu.GLUquadric;
import com.jogamp.opengl.util.texture.Texture;
import simulator.texture.TextureHandler;
____________________________________________________________________________________
this.sunTexture = sunTexture;
}
// Apply texture.
sunTexture.enable(gl);
sunTexture.bind(gl);
gl.glPushName(6);
angle = (angle + 0.7f) % 360f;
gl.glPushMatrix();
gl.glRotatef(angle, 0.8f, 0.1f, 0);
gl.glPopMatrix();
gl.glPopName();
}
CAMERA
package simulator.camera;
import com.jogamp.opengl.*;
____________________________________________________________________________________
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.fixedfunc.GLPointerFunc;
import com.jogamp.opengl.glu.GLU;
import com.jogamp.opengl.glu.GLUquadric;
import com.jogamp.opengl.util.FPSAnimator;
import com.jogamp.opengl.util.awt.TextRenderer;
import com.jogamp.opengl.util.gl2.GLUT;
import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureData;
import com.jogamp.opengl.util.texture.TextureIO;
import simulator.Planet;
import simulator.Sun;
import simulator.camera.Camera;
import simulator.texture.*;
import com.jogamp.common.nio.Buffers;
import com.jogamp.nativewindow.util.Point;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.*;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
____________________________________________________________________________________
private ArrayList<Planet> planets;
@Override
public void init(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
glu = new GLU();
planets = new ArrayList<>();
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glShadeModel(GL2.GL_SMOOTH);
gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
this.addKeyListener(this);
animator = new FPSAnimator(this, 60);
animator.start();
// adding planets
____________________________________________________________________________________
mercuryTexture = new
TextureHandler(gl,glu,"res\\\\mercurymap.jpg",true);
venusTexture = new TextureHandler(gl,glu,"res\\\\venusmap.jpg",true);
jupiterTexture = new TextureHandler(gl,glu,"res\\jupiter.jpg",true);
marsTexture = new
TextureHandler(gl,glu,"res\\mars_1k_color.jpg",true);
moonTexture = new TextureHandler(gl,glu,"res\\\\tx_0_0.png",true);
saturnTexture = new TextureHandler(gl,glu,"res\\saturn.jpg",true);
uranusTexture = new
TextureHandler(gl,glu,"res\\\\uranuscyl1.jpg",true);
neptuneTexture = new
TextureHandler(gl,glu,"res\\\\neptune_current.jpg",true);
planets.add(mercury);
planets.add(venus);
planets.add(mars);
planets.add(Jupiter);
planets.add(Saturn);
planets.add(Uranus);
planets.add(Neptune);
@Override
public void dispose(GLAutoDrawable glAutoDrawable) {
@Override
public void display(GLAutoDrawable glAutoDrawable) {
if (!animator.isAnimating()) {
return;
}
____________________________________________________________________________________
final GL2 gl = glAutoDrawable.getGL().getGL2();
setCamera(gl,300);
aimCamera(gl,glu);
moveCamera();
setLights(gl);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
sun.display();
drawEarthAndMoon(gl);
skyTexture.bind(gl);
skyTexture.enable(gl);
// skybox
drawCube(gl);
drawEarth(gl);
drawMoon(gl);
gl.glPopMatrix();
// pamant si cer
private void drawEarth(GL2 gl) {
____________________________________________________________________________________
gl.glPushName(4);
earthAngle = (earthAngle + 0.1f) % 360f;
cloudTexture.enable(gl);
cloudTexture.bind(gl);
gl.glPushMatrix();
gl.glRotatef(earthAngle, 0.2f, 0.1f, 0);
final float radius = 6.378f;
final int slices = 16;
final int stacks = 16;
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_COLOR, GL.GL_DST_ALPHA);
// clouds above the earth using a bigger sphere and applying blend to
it
GLUquadric clouds = glu.gluNewQuadric();
glu.gluQuadricOrientation(clouds, GLU.GLU_OUTSIDE);
glu.gluQuadricTexture(clouds, true);
glu.gluSphere(clouds, 7, slices, stacks);
earthTexture.enable(gl);
earthTexture.bind(gl);
gl.glDisable(GL.GL_BLEND);
gl.glPopName();
glu.gluDeleteQuadric(earth);
glu.gluDeleteQuadric(clouds);
gl.glPopMatrix();
}
// luna
private void drawMoon(GL2 gl) {
gl.glPushMatrix();
moonTexture.enable(gl);
moonTexture.bind(gl);
gl.glPushName(5);
Angle = (Angle + 1f) % 360f;
final float distance = 12.000f;
final float x = (float) Math.sin(Math.toRadians(Angle)) * distance;
final int y = (int) ((float) Math.cos(Math.toRadians(Angle)) *
distance);
final float z = 0;
____________________________________________________________________________________
gl.glTranslatef(x, y, z);
gl.glRotatef(Angle, 0, 0, -1);
gl.glRotatef(45f, 0, 1, 0);
gl.glPopMatrix();
gl.glPopName();
}
float SHINE_ALL_DIRECTIONS = 1;
float[] lightPos = { 0, 0, 0, SHINE_ALL_DIRECTIONS };
float[] lightColorAmbient = { 0.5f, 0.5f, 0.5f, 1f };
float[] lightColorSpecular = { 0.8f, 0.8f, 0.8f, 1f };
gl.glEnable(GL2.GL_LIGHT1);
gl.glEnable(GL2.GL_LIGHTING);
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width,
int height) {
GL gl = drawable.getGL();
gl.glViewport(0, 0, width, height);
}
// skybox
private void drawCube(GL gl) {
____________________________________________________________________________________
skyTexture.enable(gl);
skyTexture.bind(gl);
((GLPointerFunc) gl).glDisableClientState(GL2.GL_VERTEX_ARRAY);
final float radius = 150f;
final int slices = 16;
final int stacks = 16;
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_COLOR, GL.GL_DST_ALPHA);
GLUquadric sky = glu.gluNewQuadric();
glu.gluQuadricTexture(sky, true);
glu.gluQuadricDrawStyle(sky, GLU.GLU_FILL);
glu.gluQuadricNormals(sky, GLU.GLU_FLAT);
glu.gluQuadricOrientation(sky, GLU.GLU_INSIDE);
glu.gluSphere(sky, radius, slices, stacks);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_COLOR, GL.GL_DST_ALPHA);
}
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
cameraCoordsPosx += tmp[0];
cameraCoordsPosy += tmp[1];
cameraCoordsPosz += tmp[2];
}
____________________________________________________________________________________
float[] camUp = polarToCartesian(cameraAzimuth, 100.0f,
cameraElevation + 90);
cameraUpx = camUp[0];
cameraUpy = camUp[1];
cameraUpz = camUp[2];
// Do x-z calculation
float theta = (float) Math.toRadians(90 - azimuth);
float tantheta = (float) Math.tan(theta);
float radian_alt = (float) Math.toRadians(altitude);
float cospsi = (float) Math.cos(radian_alt);
x = -x;
if (length < 0) {
x = -x;
z = -z;
y = -y;
}
x = x * cospsi;
z = z * cospsi;
result[0] = x;
result[1] = y;
result[2] = z;
return result;
}
____________________________________________________________________________________
// miscarea camerei prin butoane
public void keyPressed(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.VK_UP) {
cameraElevation -= 2;
}
if (event.getKeyCode() == KeyEvent.VK_DOWN) {
cameraElevation += 2;
}
if (event.getKeyCode() == KeyEvent.VK_RIGHT) {
cameraAzimuth -= 2;
}
if (event.getKeyCode() == KeyEvent.VK_LEFT) {
cameraAzimuth += 2;
}
if (event.getKeyCode() == KeyEvent.VK_I) {
cameraSpeed += 0.05;
}
if (event.getKeyCode() == KeyEvent.VK_O) {
cameraSpeed -= 0.05;
}
if (event.getKeyCode() == KeyEvent.VK_S) {
cameraSpeed = 0;
}
if (event.getKeyCode() < 250)
keys[event.getKeyCode()] = true;
if (cameraAzimuth < 1)
cameraAzimuth = 359;
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
@Override
public void keyTyped(KeyEvent arg0)}}
____________________________________________________________________________________
OUTPUT
____________________________________________________________________________________
CONCLUSION
Based on the results of discussion that has been done, the authors can conclude that:
1. Animation circulation of planets around the sun interface design is the design of the visual
and interpretive models designed.
2. Application of learning visualization of the solar system was designed using API OpenGL
that can facilitate computer users to know the objects of the solar system and the solar
system information more easily
____________________________________________________________________________________