Real Software Forums
http://forums.realsoftware.com/

A solar system simulation.
http://forums.realsoftware.com/viewtopic.php?f=4&t=31518
Page 1 of 1

Author:  JustSomeGuy [ Thu Dec 10, 2009 4:19 pm ]
Post subject:  A solar system simulation.

I've ported some code from C++ to RB.
All seems to work well in this project except that the earth's and sun's texture map aren't being displayed.
The moon is fine.
http://bjobrien.dyndns.org/wikiImages/Simulation.zip

is there a manditory width/height for texture maps that I'm not respecting?
I had to convert these to from PPM to pngs so I could use them in RB.

Any idea why the sun and earth are invisible?

Author:  Blake [ Thu Dec 10, 2009 4:54 pm ]
Post subject:  Re: A solar system simulation.

You can't see the earth because of your MakeEarth method, you are setting sca(0) 3 times instead of progressing down the array. It seems to me that the sun is being drawn but you can't see it because its off screen, if I add OpenGL.glTranslatef(5.0, 0.0, 0.0) before the DrawSun call it draws but I can only see a sliver.

Image

edit: you should use gluSphere to make spheres much easier :)

Author:  JustSomeGuy [ Thu Dec 10, 2009 5:15 pm ]
Post subject:  Re: A solar system simulation.

Ya.. I had to modify the code because the Array( v, v, v) was giving me issues...
There are methods called Light(on/off) that at the moment are commented out.
I don't know why the sun is shifted... I guess i messed up on the conversion from C to RB.
I'll go over my work. cause the earth is also upside down...

glSphere? Can I map a texture onto that? If I remember right the maps have to be mapped on a vertex at a time and that is why i chose to create the sphere manually.
It was a long time ago... I did this back in 1991.

Author:  Blake [ Thu Dec 10, 2009 7:13 pm ]
Post subject:  Re: A solar system simulation.

Yeah you can texture a sphere (or any quad created with glu*) by using gluQuadricTexture( quad, true ) after binding the texture and before the gluSphere call. You will have to declare the glu calls yourself and the OpenGL module only supports gluPerspective and gluOrtho for some reason....

Author:  JustSomeGuy [ Thu Dec 10, 2009 8:08 pm ]
Post subject:  Re: A solar system simulation.

Did you look at the images in the project?
The mapping of these images to the sphere is done a vertex at a time so that the texture is mapped properly.
Anyways.. things are looking much better now.
Not perfect but I'm reasonably sure the the OpenGLSurface will do what I need it to do for my application.

Author:  JustSomeGuy [ Thu Dec 10, 2009 9:26 pm ]
Post subject:  Re: A solar system simulation.

Fixed...

For some reason the light is not pointing in the direction I think it should....
I thought I placed the light at the origin of the sun facing in the direction of the the earth... (Which is rotating about the sun.)

Seems like it's way above the sun pointing down on the North Pole of the sun and earth...

Author:  Blake [ Fri Dec 11, 2009 12:04 am ]
Post subject:  Re: A solar system simulation.

Thats because your light is directional instead of positional, change the last single in the position array to 1.0 instead of 0.0.

Author:  JustSomeGuy [ Fri Dec 11, 2009 12:13 pm ]
Post subject:  Re: A solar system simulation.

Image
Sub Lights(on as Boolean)
dim light_ambient as MemoryBlock = toMemoryBlock(Array(0.0, 0.0, 0.0, 0.0))
dim light_diffuse as MemoryBlock = toMemoryBlock(Array(1.0, 1.0, 1.0, 1.0))
dim light_specular as MemoryBlock = toMemoryBlock(Array(0.0, 0.0, 0.0, 0.0))

dim spot0_position as MemoryBlock = toMemoryBlock(Array(-1.0, 0.0, 0.0, 1.0))
dim spot0_direction as MemoryBlock = toMemoryBlock(Array(4.0, 0.0, 0.0))

if on then

OpenGL.glEnable(OpenGL.GL_LIGHTING)
OpenGL.glEnable(OpenGL.GL_LIGHT0)
OpenGL.glLightfv(OpenGL.GL_LIGHT0, OpenGL.GL_AMBIENT, light_ambient)
OpenGL.glLightfv(OpenGL.GL_LIGHT0, OpenGL.GL_DIFFUSE, light_diffuse)
OpenGL.glLightfv(OpenGL.GL_LIGHT0, OpenGL.GL_SPECULAR, light_specular)
OpenGL.glLightfv(OpenGL.GL_LIGHT0, OpenGL.GL_POSITION, spot0_position)
OpenGL.glLightfv(OpenGL.GL_LIGHT0, OpenGL.GL_SPOT_DIRECTION, spot0_direction)
OpenGL.glLightf(OpenGL.GL_LIGHT0, OpenGL.GL_SPOT_CUTOFF, 0.0)

else

OpenGL.glDisable(OpenGL.GL_LIGHTING)
OpenGL.glDisable(OpenGL.GL_LIGHT0)

end if

End Sub



I tried that... Did it work for you?

Author:  Blake [ Fri Dec 11, 2009 12:44 pm ]
Post subject:  Re: A solar system simulation.

There was some code to adjust, blocking the spotlight lightf calls. Don't forget to call Lights(true/false) in the render event of the OGLSurface, it wasn't be called at all with the lines commented out so nothing was getting setup.

Image

Sub Lights(on as Boolean)
dim light_ambient as MemoryBlock = toMemoryBlock(Array(0.0, 0.0, 0.0, 0.0))
dim light_diffuse as MemoryBlock = toMemoryBlock(Array(1.0, 1.0, 1.0, 1.0))
dim light_specular as MemoryBlock = toMemoryBlock(Array(1.0, 1.0, 1.0, 1.0))

dim spot0_position as MemoryBlock = toMemoryBlock(Array(0.0, 0.0, 0.0, 1.0))
dim spot0_direction as MemoryBlock = toMemoryBlock(Array(4.0, 0.0, 0.0))

if on then

OpenGL.glEnable(OpenGL.GL_LIGHTING)
OpenGL.glEnable(OpenGL.GL_LIGHT0)
OpenGL.glLightfv(OpenGL.GL_LIGHT0, OpenGL.GL_AMBIENT, light_ambient)
OpenGL.glLightfv(OpenGL.GL_LIGHT0, OpenGL.GL_DIFFUSE, light_diffuse)
OpenGL.glLightfv(OpenGL.GL_LIGHT0, OpenGL.GL_SPECULAR, light_specular)
OpenGL.glLightfv(OpenGL.GL_LIGHT0, OpenGL.GL_POSITION, spot0_position)
//OpenGL.glLightfv(OpenGL.GL_LIGHT0, OpenGL.GL_SPOT_DIRECTION, spot0_direction)
//OpenGL.glLightf(OpenGL.GL_LIGHT0, OpenGL.GL_SPOT_CUTOFF, 0.0)

else

OpenGL.glDisable(OpenGL.GL_LIGHTING)
OpenGL.glDisable(OpenGL.GL_LIGHT0)

end if

End Sub

Function Render() As Boolean
dim scale as single =4.0

day = day + (1 * scale)
if (day > 360.0) then day = day - 360.0

month = month + (.5 * scale)
if (month > 360.0) then month = month - 360.0

year = year + (0.041067762 * scale)
if (year > 360.0) then year = year - 360.0

OpenGL.glClear(OpenGL.GL_COLOR_BUFFER_BIT or OpenGL.GL_DEPTH_BUFFER_BIT)

OpenGL.glPushMatrix()
Lights(false)

DrawSun()
OpenGL.glRotatef(year, 0.0, 0.0, 1.0) 'Revolve earth around sun

Lights(true)

OpenGL.glTranslatef(5.0, 0.0, 0.0) 'Push earth into its orbig.

OpenGL.glPushMatrix()
OpenGL.glRotatef(-year, 0.0, 0.0, 1.0) 'Tilt the earth.
OpenGL.glRotatef(23.45, 0.0, 1.0, 0.0)
OpenGL.glRotatef(-day, 0.0, 0.0, -1.0) 'Rotate earth about itself
DrawEarth()
OpenGL.glPopMatrix()

OpenGL.glRotatef(month, 0.0, 0.0, 1.0)
OpenGL.glTranslatef(1.0, 0.0, 0.0)
DrawMoon()

OpenGL.glPopMatrix()

OpenGL.glFlush()
'OpenGL.SwapBuffers '(ghDC)




End Function

Author:  JustSomeGuy [ Fri Dec 11, 2009 1:14 pm ]
Post subject:  Re: A solar system simulation.

Thanks! :D

Author:  JustSomeGuy [ Fri Dec 11, 2009 10:04 pm ]
Post subject:  Re: A solar system simulation.

By the way.. Why does render return a bool?

Author:  Blake [ Sat Dec 12, 2009 2:52 am ]
Post subject:  Re: A solar system simulation.

You know, thats a great question, I can't imagine what the difference would be by returning true or false....

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/