Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Dec 14, 2019 7:07 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: A solar system simulation.
PostPosted: Thu Dec 10, 2009 4:19 pm 
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?


Top
  
Reply with quote  
 Post subject: Re: A solar system simulation.
PostPosted: Thu Dec 10, 2009 4:54 pm 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
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 :)

_________________
Open Source OpenGL Classes:
Camera (1.1), Light (1.0), Texture (1.2), Font (1.2), Mesh (1.7), Models (1.0)


Top
 Profile  
Reply with quote  
 Post subject: Re: A solar system simulation.
PostPosted: Thu Dec 10, 2009 5:15 pm 
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.


Top
  
Reply with quote  
 Post subject: Re: A solar system simulation.
PostPosted: Thu Dec 10, 2009 7:13 pm 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
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....

_________________
Open Source OpenGL Classes:
Camera (1.1), Light (1.0), Texture (1.2), Font (1.2), Mesh (1.7), Models (1.0)


Top
 Profile  
Reply with quote  
 Post subject: Re: A solar system simulation.
PostPosted: Thu Dec 10, 2009 8:08 pm 
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.


Top
  
Reply with quote  
 Post subject: Re: A solar system simulation.
PostPosted: Thu Dec 10, 2009 9:26 pm 
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...


Top
  
Reply with quote  
 Post subject: Re: A solar system simulation.
PostPosted: Fri Dec 11, 2009 12:04 am 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
Thats because your light is directional instead of positional, change the last single in the position array to 1.0 instead of 0.0.

_________________
Open Source OpenGL Classes:
Camera (1.1), Light (1.0), Texture (1.2), Font (1.2), Mesh (1.7), Models (1.0)


Top
 Profile  
Reply with quote  
 Post subject: Re: A solar system simulation.
PostPosted: Fri Dec 11, 2009 12:13 pm 
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?


Top
  
Reply with quote  
 Post subject: Re: A solar system simulation.
PostPosted: Fri Dec 11, 2009 12:44 pm 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
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

_________________
Open Source OpenGL Classes:
Camera (1.1), Light (1.0), Texture (1.2), Font (1.2), Mesh (1.7), Models (1.0)


Top
 Profile  
Reply with quote  
 Post subject: Re: A solar system simulation.
PostPosted: Fri Dec 11, 2009 1:14 pm 
Thanks! :D


Top
  
Reply with quote  
 Post subject: Re: A solar system simulation.
PostPosted: Fri Dec 11, 2009 10:04 pm 
By the way.. Why does render return a bool?


Top
  
Reply with quote  
 Post subject: Re: A solar system simulation.
PostPosted: Sat Dec 12, 2009 2:52 am 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
You know, thats a great question, I can't imagine what the difference would be by returning true or false....

_________________
Open Source OpenGL Classes:
Camera (1.1), Light (1.0), Texture (1.2), Font (1.2), Mesh (1.7), Models (1.0)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group