Saturday, July 19, 2008

Simple Solar System in OpenGL




I have created a simple Solar System using OpenGL




#include <stdlib.h>
#include <GLUT/glut.h>
#include <math.h>
#include <stdio.h>

static float Xvalue = 0.0, Yvalue = 0.0, Angle = 0.0;

int MoveX = 0;
int MoveY = 0;

void myInit(void) {
glClearColor (0.0, 0.0, 0.0, 0.0);
}


static float x1[360][2];
static float x2[360][2];
static float x3[720][2];


void generateCircle()
{
int i = 0;

for(i=0; i <= 360; i++)
{
x1[i][0] = sin(i*3.1416/180)*3;
x1[i][1] = cos(i*3.1416/180)*3;
}

for(i=0; i <= 360; i++)
{
x2[i][0] = sin(i*3.1416/180)*1;
x2[i][1] = cos(i*3.1416/180)*1;
}

for(i=0; i <= 720; i++)
{
x3[i][0] = sin(i*3.1416/180)*5;
x3[i][1] = cos(i*3.1416/180)*5;
}

}




void myDisplay(void) {

glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);

//sun
glPushMatrix();
gluLookAt (0.0, 10.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
glTranslatef(Xvalue, 0.0, Yvalue);
glRotatef(Angle, 0.0, 0.0, 1.0);
glutWireSphere (0.5, 15, 15);
glPopMatrix();

glPushMatrix();
gluLookAt (0.0, 10.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
if(MoveX==360)
MoveX = 0;
glTranslatef(x1[MoveX][1], x1[MoveX][0], 0.0);
glRotatef(Angle, 0.0, 0.0, 1.0);
glutWireSphere (0.4, 15, 15);
glTranslatef(x2[MoveX][0], x2[MoveX][1], 0.0);
glutWireSphere (0.2, 15, 15);
glPopMatrix();

glPushMatrix();
gluLookAt (0.0, 10.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
if(MoveY==720)
MoveY = 0;
glTranslatef(x3[MoveY/2][1], x3[MoveY/2][0], 0.0);
glRotatef(Angle, 0.0, 0.0, 1.0);
glutWireSphere (0.4, 15, 15);
int i = 0;
//glBegin(GL_LINE_STRIP);
glBegin(GL_QUAD_STRIP);
for(i=0; i <= 360; i++)
{
glVertex3f(sin(i*3.1416/180)*0.5, cos(i*3.1416/180)*0.5, 0 );
glVertex3f(sin(i*3.1416/180)*0.7, cos(i*3.1416/180)*0.7, 0 );
}
glEnd();
glRotatef(Angle, 0.0, 0.0, 1.0);
glPopMatrix();

glFlush ();
}


void resize(int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
}


void animation()
{
Angle += 15.0;
glutPostRedisplay();
MoveX +=1;
MoveY +=1;
glutPostRedisplay();
glutTimerFunc(100, animation, 0);

}


int main(int argc, char ** argv){

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(1024, 768);
glutInitWindowPosition(100, 150);
glutCreateWindow("OpenGL");
myInit();
glutDisplayFunc(myDisplay);
glutReshapeFunc(resize);
generateCircle();
glutTimerFunc(100, animation, 0);
glutMainLoop();
}


Tuesday, July 01, 2008

iReport java.lang.NullPointerException

I was facing some problem to start iReport in my Debian

salahuddin@crab:~/iReport-2.0.3$ ./iReport.sh
Exception in thread "main" java.lang.NullPointerException
at java.util.Hashtable.put(libgcj.so.70)
at javax.swing.plaf.basic.BasicToolBarUI.setBorderToRollover(libgcj.so.70)
at javax.swing.plaf.basic.BasicToolBarUI$ToolBarContListener.componentAdded(libgcj.so.70)
at java.awt.Container.addImpl(libgcj.so.70)
at javax.swing.JToolBar.addImpl(libgcj.so.70)
at java.awt.Container.add(libgcj.so.70)
at it.businesslogic.ireport.gui.ToolbarFormatPanel.initComponents(ToolbarFormatPanel.java:170)
at it.businesslogic.ireport.gui.ToolbarFormatPanel.(ToolbarFormatPanel.java:57)
at it.businesslogic.ireport.gui.MainFrame.(MainFrame.java:487)
at it.businesslogic.ireport.gui.MainFrame.main(MainFrame.java:8020)
salahuddin@crab:~/iReport-2.0.3$


Here is my .bashrc
export CVSROOT=:ext:salahuddin@paq:/home/cvs
export CVS_RSH=/usr/bin/ssh
export ANT_OPTS=-Xmx512m
export ANT_HOME=/usr/ant
export JAVA_HOME=/usr/jdk1.5.0_03
export CLASS_PATH=$JAVA_HOME/lib/:$JAVA_HOME/jre/lib
export CLASSPATH=$JAVA_HOME/lib/:$JAVA_HOME/jre/lib
export PATH=$PATH:$ANT_HOME/bin:$JAVA_HOME/bin
export CATALINA_HOME=/usr/tomcat
export CVSEDITOR=vim

Note: My /usr/java is soft linked with
/usr/jdk1.5.0_03

Main problem /usr/bin/java was linked with
/etc/alternatives/java
salahuddin@crab:/usr/bin$ ls -l java*
lrwxrwxrwx 1 root root 22 2008-04-30 22:29 java -> /etc/alternatives/java
lrwxrwxrwx 1 root root 23 2008-06-26 15:52 javac -> /etc/alternatives/javac
lrwxrwxrwx 1 root root 25 2008-07-01 15:58 javadoc -> /etc/alternatives/javadoc
lrwxrwxrwx 1 root root 23 2008-06-26 15:52 javah -> /etc/alternatives/javah

The main problem was it was using java from the gij package/

#cd /usr/bin/
#mv java java2
#mv javac javac2
#mv javah javah2
#mv javadoc javadoc2

#ln -s /usr/java/bin/java
/usr/bin/java
#ln -s /usr/java/bin/javac /usr/bin/javac
#ln -s /usr/java/bin/javah /usr/bin/javah
#ln -s /usr/java/bin/javadoc /usr/bin/javadoc

It simply solve the problem.