#!/bin/env python # Copyright (C) 2002-2003 Gideon May (gideon@computer.org) # # Permission to copy, use, sell and distribute this software is granted # provided this copyright notice appears in all copies. # Permission to modify the code and to distribute modified code is granted # provided this copyright notice appears in all copies, and a notice # that the code was modified is included with the copyright notice. # # This software is provided "as is" without express or implied warranty, # and with no claim as to its suitability for any purpose. # -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield # # This application is open source and may be redistributed and/or modified # freely and without restriction, both in commericial and non commericial applications, # as long as this copyright notice is maintained. # # This application is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # from PyOSG import osg from PyOSG import osgDB import math import OpenGL def makeSky(): lev = ( -5, -1.0, 1.0, 15.0, 30.0, 60.0, 90.0 ) cc = ( ( 0.0, 0.0, 0.15 ), ( 0.0, 0.0, 0.15 ), ( 0.4, 0.4, 0.7 ), ( 0.2, 0.2, 0.6 ), ( 0.1, 0.1, 0.6 ), ( 0.1, 0.1, 0.6 ), ( 0.1, 0.1, 0.6 ) ) radius = 20.0 nlev = len(lev) geom = osg.Geometry() coords = osg.Vec3Array(19*nlev) colors = osg.Vec4Array(19*nlev) tcoords = osg.Vec2Array(19*nlev) ci = 0 for i in range(nlev): for j in range(19): alpha = osg.DegreesToRadians(lev[i]) theta = osg.DegreesToRadians(j*20) x = radius * math.cos( alpha ) * math.cos( theta ) y = radius * math.cos( alpha ) * -math.sin( theta ) z = radius * math.sin( alpha ) coords[ci][0] = x coords[ci][1] = y coords[ci][2] = z colors[ci][0] = cc[i][0] colors[ci][1] = cc[i][1] colors[ci][2] = cc[i][2] colors[ci][3] = 1.0 tcoords[ci][0] = j/18.0 tcoords[ci][0] = i/(nlev-1.0) ci += 1 for i in range(nlev-1): drawElements = osg.DrawElementsUShort(osg.PrimitiveSet.TRIANGLE_STRIP) drawElements.reserve(38) for j in range(19): drawElements.push_back((i+1)*19+j) drawElements.push_back((i+0)*19+j) geom.addPrimitiveSet(drawElements) geom.setVertexArray( coords ) geom.setTexCoordArray( 0, tcoords ) geom.setColorArray( colors ) geom.setColorBinding( osg.Geometry.BIND_PER_VERTEX ) tex = osg.Texture2D() tex.setImage(osgDB.readImageFile("Images/white.rgb")) dstate = osg.StateSet() dstate.setTextureAttributeAndModes(0, tex, osg.StateAttribute.OFF ) dstate.setTextureAttribute(0, osg.TexEnv()) dstate.setMode( OpenGL.GL.GL_LIGHTING, osg.StateAttribute.OFF ) dstate.setMode( OpenGL.GL.GL_CULL_FACE, osg.StateAttribute.ON ) # clear the depth to the far plane. depth = osg.Depth() depth.setFunction(osg.Depth.ALWAYS) depth.setRange(1.0,1.0) dstate.setAttributeAndModes(depth,osg.StateAttribute.ON ) dstate.setRenderBinDetails(-2,"RenderBin") geom.setStateSet( dstate ) geode = osg.Geode() geode.addDrawable( geom ) geode.setName( "Sky" ) return geode if __name__ == "__main__": sky = makeSky() from PyOSG import * viewer = osgProducer.Viewer() viewer.setUpViewer(osgProducer.Viewer.STANDARD_SETTINGS) viewer.setSceneData(sky) viewer.realize() while not viewer.done(): viewer.sync() viewer.update() viewer.frame() viewer.sync() sys.exit(0)