def createTouchRepresentations(parent_group, num_objects): # create some geometry which is shown for every touch-point for(unsigned int i = 0 i not = num_objects ++i) ss = std.ostringstream() geode = osg.Geode() drawable = osg.ShapeDrawable(osg.Box(osg.Vec3(0,0,0), 100)) drawable.setColor(osg.Vec4(0.5, 0.5, 0.5,1)) geode.addDrawable(drawable) ss, "Touch ", i text = osgText.Text() geode.addDrawable( text ) drawable.setDataVariance(osg.Object.DYNAMIC) _drawables.push_back(drawable) text.setFont("fonts/arial.ttf") text.setPosition(osg.Vec3(110,0,0)) text.setText(ss.str()) _texts.push_back(text) text.setDataVariance(osg.Object.DYNAMIC) mat = osg.MatrixTransform() mat.addChild(geode) mat.setNodeMask(0x0) _mats.push_back(mat) parent_group.addChild(mat)
def createAutoScale(position, characterSize, message, minScale, maxScale): timesFont = str("fonts/arial.ttf") text = osgText.Text() text.setCharacterSize(characterSize) text.setText(message) text.setFont(timesFont) text.setAlignment(osgText.Text.CENTER_CENTER) geode = osg.Geode() geode.addDrawable(text) geode.getOrCreateStateSet().setMode(GL_LIGHTING, osg.StateAttribute.OFF) at = osg.AutoTransform() at.addChild(geode) at.setAutoRotateMode(osg.AutoTransform.ROTATE_TO_SCREEN) at.setAutoScaleToScreen(True) at.setMinimumScale(minScale) at.setMaximumScale(maxScale) at.setPosition(position) return at
class UserEventHandler (osgGA.GUIEventHandler) : UserEventHandler(osgText.Text* text) : osgGA.GUIEventHandler(), _text(text) ~UserEventHandler() handle = bool( osgGA.GUIEventAdapter ea,osgGA.GUIActionAdapter aa) _text = osgText.Text()
def createText(str, pos): # text drawable text = osgText.Text() text.setFont(str("fonts/arial.ttf")) text.setPosition(pos) text.setText(str) # geode geode = osg.Geode() geode.addDrawable(text) return geode
def createLabel(pos, size, label, axisAlignment): geode = osg.Geode() timesFont = str("fonts/arial.ttf") text = osgText.Text() geode.addDrawable( text ) text.setFont(timesFont) text.setPosition(pos) text.setCharacterSize(size) text.setAxisAlignment(axisAlignment) text.setAlignment(osgText.Text.CENTER_CENTER) text.setText(label)
def createText(str, pos): static str font("fonts/arial.ttf") geode = osg.Geode() text = osgText.Text() geode.addDrawable(text) text.setFont(font) text.setPosition(pos) text.setText(str) return geode
def createHUD(w, h): # create a camera to set up the projection and model view matrices, and the subgraph to draw in the HUD camera = osg.Camera() # set the projection matrix camera.setProjectionMatrix(osg.Matrix.ortho2D(0,w,0,h)) # set the view matrix camera.setReferenceFrame(osg.Transform.ABSOLUTE_RF) camera.setViewMatrix(osg.Matrix.identity()) # only clear the depth buffer camera.setClearMask(GL_DEPTH_BUFFER_BIT) # draw subgraph after main camera view. camera.setRenderOrder(osg.Camera.POST_RENDER) # we don't want the camera to grab event focus from the viewers main camera(s). camera.setAllowEventFocus(False) # add to this camera a subgraph to render geode = osg.Geode() timesFont = str("fonts/arial.ttf") # turn lighting off for the text and disable depth test to ensure it's always ontop. stateset = geode.getOrCreateStateSet() stateset.setMode(GL_LIGHTING,osg.StateAttribute.OFF) position = osg.Vec3(50.0,h-50,0.0) text = osgText.Text() geode.addDrawable( text ) text.setFont(timesFont) text.setPosition(position) text.setText("A simple multi-touch-example\n1 touch = rotate, \n2 touches = drag + scale, \n3 touches = home")
def createLabel3(pos, size, label): geode = osg.Geode() timesFont = str("fonts/arial.ttf") text = osgText.Text() geode.addDrawable( text ) text.setFont(timesFont) text.setPosition(pos) text.setFontResolution(40,40) text.setCharacterSize(size) text.setAlignment(osgText.Text.CENTER_CENTER) text.setAutoRotateToScreen(True) text.setCharacterSizeMode(osgText.Text.OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT) text.setText(label)
def createHUD(label): # create a camera to set up the projection and model view matrices, and the subgraph to drawn in the HUD camera = osg.Camera() # set the projection matrix camera.setProjectionMatrix(osg.Matrix.ortho2D(0,1280,0,1024)) # set the view matrix camera.setReferenceFrame(osg.Transform.ABSOLUTE_RF) camera.setViewMatrix(osg.Matrix.identity()) # only clear the depth buffer camera.setClearMask(GL_DEPTH_BUFFER_BIT) # draw subgraph after main camera view. camera.setRenderOrder(osg.Camera.POST_RENDER) # we don't want the camera to grab event focus from the viewers main camera(s). camera.setAllowEventFocus(False) # add to this camera a subgraph to render geode = osg.Geode() font = str("fonts/arial.ttf") # turn lighting off for the text and disable depth test to ensure its always ontop. stateset = geode.getOrCreateStateSet() stateset.setMode(GL_LIGHTING,osg.StateAttribute.OFF) position = osg.Vec3(150.0,150.0,0.0) text = osgText.Text() geode.addDrawable( text ) text.setFont(font) text.setPosition(position) text.setCharacterSize(100.0) text.setText(label) camera.addChild(geode)
class KeyboardModel (osg.Referenced) : KeyboardModel() createKeyboard() def getScene(): return _scene keyChange = void(int key, int virtualKey, int value) ~KeyboardModel() addKey = osg.Switch*(osg.Vec3 pos, int key, str text,float width, float height) createKeyboard = void() typedef std.map<int, osg.Switch > KeyModelMap _scene = osg.Group() _keyModelMap = KeyModelMap() _inputText = osgText.Text()
def main(argv): if argc<=1 : readConfFile("osg.conf") # read ConfigFile 1 else: readConfFile(argv[1]) # read ConfigFile 1 # construct the viewer. viewer = osgViewer.Viewer() updateText = osgText.Text() updateText.setDataVariance(osg.Object.DYNAMIC) # add the handler for doing the picking viewer.addEventHandler(PickHandler(viewer,updateText)) root = osg.Group() root.addChild( setupGraph() ) # add the HUD subgraph. root.addChild(createHUD(updateText)) # add model to viewer. viewer.setSceneData( root ) lookAt = osg.Matrix() lookAt.makeLookAt(osg.Vec3(0.0, -4.0, 0.0), centerScope, osg.Vec3(0.0, 0.0, 1.0)) viewer.getCamera().setViewMatrix(lookAt) viewer.realize() while not viewer.done() : # fire off the cull and draw traversals of the scene. viewer.frame() return 0
def createHUD(updateText): # create the hud. derived from osgHud.cpp # adds a set of quads, each in a separate Geode - which can be picked individually # eg to be used as a menuing/help system not # Can pick texts too not hudCamera = osg.Camera() hudCamera.setReferenceFrame(osg.Transform.ABSOLUTE_RF) hudCamera.setProjectionMatrixAsOrtho2D(0,1280,0,1024) hudCamera.setViewMatrix(osg.Matrix.identity()) hudCamera.setRenderOrder(osg.Camera.POST_RENDER) hudCamera.setClearMask(GL_DEPTH_BUFFER_BIT) timesFont = str("fonts/times.ttf") # turn lighting off for the text and disable depth test to ensure its always ontop. position = osg.Vec3(150.0,800.0,0.0) delta = osg.Vec3(0.0,-60.0,0.0) geode = osg.Geode() stateset = geode.getOrCreateStateSet() stateset.setMode(GL_LIGHTING,osg.StateAttribute.OFF) stateset.setMode(GL_DEPTH_TEST,osg.StateAttribute.OFF) geode.setName("simple") hudCamera.addChild(geode) text = osgText.Text() geode.addDrawable( text ) text.setFont(timesFont) text.setText("Picking in Head Up Displays is simple not ") text.setPosition(position) position += delta
def createHUDText(): rootNode = osg.Group() font = osgText.Font(osgQt.QFontImplementation(QFont("Arial"))) geode = osg.Geode() rootNode.addChild(geode) windowHeight = 1024.0 windowWidth = 1280.0 margin = 50.0 #################################################### # # Examples of how to set up different text layout # layoutColor = osg.Vec4(1.0,1.0,0.0,1.0) layoutCharacterSize = 20.0 text = osgText.Text() text.setFont(font) text.setColor(layoutColor) text.setCharacterSize(layoutCharacterSize) text.setPosition(osg.Vec3(margin,windowHeight-margin,0.0)) # the default layout is left to right, typically used in languages # originating from europe such as English, French, German, Spanish etc.. text.setLayout(osgText.Text.LEFT_TO_RIGHT) text.setText("text.setLayout(osgText.Text.LEFT_TO_RIGHT)") geode.addDrawable(text) text = osgText.Text() text.setFont(font) text.setColor(layoutColor) text.setCharacterSize(layoutCharacterSize) text.setPosition(osg.Vec3(windowWidth-margin,windowHeight-margin,0.0)) # right to left layouts would be used for hebrew or arabic fonts. text.setLayout(osgText.Text.RIGHT_TO_LEFT) text.setAlignment(osgText.Text.RIGHT_BASE_LINE) text.setText("text.setLayout(osgText.Text.RIGHT_TO_LEFT)") geode.addDrawable(text) text = osgText.Text() text.setFont(font) text.setColor(layoutColor) text.setPosition(osg.Vec3(margin,windowHeight-margin,0.0)) text.setCharacterSize(layoutCharacterSize) # vertical font layout would be used for asian fonts. text.setLayout(osgText.Text.VERTICAL) text.setText("text.setLayout(osgText.Text.VERTICAL)") geode.addDrawable(text)
def create3DText(center, radius): geode = osg.Geode() #################################################### # # Examples of how to set up axis/orientation alignments # characterSize = radius*0.2 pos = osg.Vec3(center.x()-radius*.5,center.y()-radius*.5,center.z()-radius*.5) text1 = osgText.Text() text1.setFont(osgText.Font(osgQt.QFontImplementation(QFont("Times")))) text1.setCharacterSize(characterSize) text1.setPosition(pos) text1.setAxisAlignment(osgText.Text.XY_PLANE) text1.setText("XY_PLANE") geode.addDrawable(text1) text2 = osgText.Text() text2.setFont(osgText.Font(osgQt.QFontImplementation(QFont("Times")))) text2.setCharacterSize(characterSize) text2.setPosition(pos) text2.setAxisAlignment(osgText.Text.YZ_PLANE) text2.setText("YZ_PLANE") geode.addDrawable(text2) text3 = osgText.Text() text3.setFont(osgText.Font(osgQt.QFontImplementation(QFont("Times")))) text3.setCharacterSize(characterSize) text3.setPosition(pos) text3.setAxisAlignment(osgText.Text.XZ_PLANE) text3.setText("XZ_PLANE") geode.addDrawable(text3) text4 = osgText.Text() text4.setFont(osgText.Font(osgQt.QFontImplementation(QFont("Times")))) text4.setCharacterSize(characterSize) text4.setPosition(center) text4.setAxisAlignment(osgText.Text.SCREEN) characterSizeModeColor = osg.Vec4(1.0,0.0,0.5,1.0) text5 = osgText.Text() text5.setColor(characterSizeModeColor) text5.setFont(osgText.Font(osgQt.QFontImplementation(QFont("Times")))) #text5.setCharacterSize(characterSize) text5.setCharacterSize(32.0) # medium text5.setPosition(center - osg.Vec3(0.0, 0.0, 0.2)) text5.setAxisAlignment(osgText.Text.SCREEN) text5.setCharacterSizeMode(osgText.Text.SCREEN_COORDS) text5.setText("CharacterSizeMode SCREEN_COORDS(size 32.0)") geode.addDrawable(text5) text6 = osgText.Text() text6.setColor(characterSizeModeColor) text6.setFont(osgText.Font(osgQt.QFontImplementation(QFont("Times")))) text6.setCharacterSize(characterSize) text6.setPosition(center - osg.Vec3(0.0, 0.0, 0.4)) text6.setAxisAlignment(osgText.Text.SCREEN) text6.setCharacterSizeMode(osgText.Text.OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT) text6.setText("CharacterSizeMode OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT") geode.addDrawable(text6) text7 = osgText.Text() text7.setColor(characterSizeModeColor) text7.setFont(osgText.Font(osgQt.QFontImplementation(QFont("Times")))) text7.setCharacterSize(characterSize) text7.setPosition(center - osg.Vec3(0.0, 0.0, 0.6)) text7.setAxisAlignment(osgText.Text.SCREEN) text7.setCharacterSizeMode(osgText.Text.OBJECT_COORDS) text7.setText("CharacterSizeMode OBJECT_COORDS (default)") geode.addDrawable(text7) #if 1 # reproduce outline bounding box compute problem with backdrop on. text4.setBackdropType(osgText.Text.OUTLINE) text4.setDrawMode(osgText.Text.TEXT | osgText.Text.BOUNDINGBOX) #endif text4.setText("SCREEN") geode.addDrawable(text4) shape = osg.ShapeDrawable(osg.Sphere(center,characterSize*0.2)) shape.getOrCreateStateSet().setMode(GL_LIGHTING,osg.StateAttribute.ON) geode.addDrawable(shape) rootNode = osg.Group() rootNode.addChild(geode) return rootNode
text.setText("text.setLayout(osgText.Text.VERTICAL)") geode.addDrawable(text) #################################################### # # Examples of how to set up different font resolution # fontSizeColor = osg.Vec4(0.0,1.0,1.0,1.0) fontSizeCharacterSize = 30 cursor = osg.Vec3(margin*2,windowHeight-margin*2,0.0) text = osgText.Text() text.setFont(font) text.setColor(fontSizeColor) text.setCharacterSize(fontSizeCharacterSize) text.setPosition(cursor) # use text that uses 10 by 10 texels as a target resolution for fonts. text.setFontResolution(10,10) # blocky but small texture memory usage text.setText("text.setFontResolution(10,10) # blocky but small texture memory usage") geode.addDrawable(text) cursor.y() -= fontSizeCharacterSize text = osgText.Text() text.setFont(font) text.setColor(fontSizeColor)
def main(argv): # use an ArgumentParser object to manage the program arguments. arguments = osg.ArgumentParser(argv) # read the scene from the list of file specified commandline args. scene = osgDB.readNodeFiles(arguments) if not scene and arguments.read("--relative-camera-scene") : # Create a test scene with a camera that has a relative reference frame. group = osg.Group() sphere = osg.Geode() sphere.setName("Sphere") sphere.addDrawable(osg.ShapeDrawable(osg.Sphere())) cube = osg.Geode() cube.setName("Cube") cube.addDrawable(osg.ShapeDrawable(osg.Box())) camera = osg.Camera() camera.setRenderOrder(osg.Camera.POST_RENDER) camera.setClearMask(GL_DEPTH_BUFFER_BIT) camera.setReferenceFrame(osg.Transform.RELATIVE_RF) camera.setViewMatrix(osg.Matrix.translate(-2, 0, 0)) xform = osg.MatrixTransform(osg.Matrix.translate(1, 1, 1)) xform.addChild(camera) group.addChild(sphere) group.addChild(xform) camera.addChild(cube) scene = group # if not loaded assume no arguments passed in, try use default mode instead. if not scene : scene = osgDB.readNodeFile("fountain.osgt") group = dynamic_cast<osg.Group*>(scene) if not group : group = osg.Group() group.addChild(scene) updateText = osgText.Text() # add the HUD subgraph. group.addChild(createHUD(updateText)) if arguments.read("--CompositeViewer") : view = osgViewer.View() # add the handler for doing the picking view.addEventHandler(PickHandler(updateText)) # set the scene to render view.setSceneData(group) view.setUpViewAcrossAllScreens() viewer = osgViewer.CompositeViewer() viewer.addView(view) return viewer.run() else: viewer = osgViewer.Viewer() # add all the camera manipulators keyswitchManipulator = osgGA.KeySwitchMatrixManipulator() keyswitchManipulator.addMatrixManipulator( ord("1"), "Trackball", osgGA.TrackballManipulator() ) keyswitchManipulator.addMatrixManipulator( ord("2"), "Flight", osgGA.FlightManipulator() ) keyswitchManipulator.addMatrixManipulator( ord("3"), "Drive", osgGA.DriveManipulator() ) num = keyswitchManipulator.getNumMatrixManipulators() keyswitchManipulator.addMatrixManipulator( ord("4"), "Terrain", osgGA.TerrainManipulator() ) pathfile = str() keyForAnimationPath = ord("5") while arguments.read("-p",pathfile) : apm = osgGA.AnimationPathManipulator(pathfile) if apm or not apm.valid() : num = keyswitchManipulator.getNumMatrixManipulators() keyswitchManipulator.addMatrixManipulator( keyForAnimationPath, "Path", apm ) ++keyForAnimationPath keyswitchManipulator.selectMatrixManipulator(num) viewer.setCameraManipulator( keyswitchManipulator ) # add the handler for doing the picking viewer.addEventHandler(PickHandler(updateText)) # set the scene to render viewer.setSceneData(group) return viewer.run()
PickHandler(osgText.Text* updateText): _updateText(updateText) ~PickHandler() handle = bool( osgGA.GUIEventAdapter ea,osgGA.GUIActionAdapter aa) pick = virtual void(osgViewer.View* view, osgGA.GUIEventAdapter ea) def setLabel(name): if _updateText : _updateText.setText(name) _updateText = osgText.Text() bool PickHandler.handle( osgGA.GUIEventAdapter ea,osgGA.GUIActionAdapter aa) switch(ea.getEventType()) case(osgGA.GUIEventAdapter.PUSH): view = dynamic_cast<osgViewer.View*>(aa) if view : pick(view,ea) return False case(osgGA.GUIEventAdapter.KEYDOWN): if ea.getKey()==ord("c") : view = dynamic_cast<osgViewer.View*>(aa) event = osgGA.GUIEventAdapter(ea) event.setX((ea.getXmin()+ea.getXmax())*0.5) event.setY((ea.getYmin()+ea.getYmax())*0.5) if view : pick(view,*event)
geom.addPrimitiveSet(osg.DrawArrays(GL_POLYGON,0,vertices.getNumElements())) tessellator = osgUtil.Tessellator() tessellator.retessellatePolygons(*geom) return geom osg. Node* createTextBelow( osg.BoundingBox bb, str label, str) geode = osg.Geode() font = str("fonts/arial.ttf") text = osgText.Text() text.setFont(font) text.setFontResolution(64,64) text.setAlignment(osgText.Text.CENTER_CENTER) text.setAxisAlignment(osgText.Text.XZ_PLANE) text.setPosition(bb.center()-osg.Vec3(0.0,0.0,(bb.zMax()-bb.zMin()))) text.setColor(osg.Vec4(0.37,0.48,0.67,1.0)) text.setText(label) geode.addDrawable( text ) return geode osg. Node* createTextLeft( osg.BoundingBox bb, str label, str subscript) geode = osg.Geode()
camera = ref_ptr<Camera>() # text displayed on the screen showing the user's choices textProjection = ref_ptr<Projection>() configText = ref_ptr<osgText.Text>() zNearText = ref_ptr<osgText.Text>() textNotAvailable = ref_ptr<Geode>() textInverted = ref_ptr<Geode>() AppState.AppState(osgViewer.Viewer* viewer_) : displayScene(True), invertRange(True), currentConfig(0), viewer(viewer_), zNear(0.03125) sw = Switch() fontName = string("fonts/arial.ttf") # Text description of current config configText = osgText.Text() configText.setDataVariance(Object.DYNAMIC) configText.setFont(fontName) configText.setPosition(Vec3(50.0, 50.0, 0.0)) configText.setColor(Vec4(1.0, 1.0, 1.0, 1.0)) textGeode = Geode() textGeode.addDrawable(configText) # Text for the near plane distance zNearText = osgText.Text() zNearText.setDataVariance(Object.DYNAMIC) zNearText.setFont(fontName) zNearText.setPosition(Vec3(1230.0, 50.0, 0.0)) zNearText.setColor(Vec4(1.0, 1.0, 1.0, 1.0)) zNearText.setAlignment(osgText.Text.RIGHT_BASE_LINE) textGeode.addDrawable(zNearText) # Projection that lets the text be placed in pixels.
caption_("Frame") Frame.Frame( Frame copy, osg.CopyOp copyop) : osg.Geode(copy, copyop), bgcolor_(copy.bgcolor_), rect_(copy.rect_), caption_(copy.caption_) void Frame.rebuild() zPos = -0.1 removeDrawables(0, getNumDrawables()) addDrawable(build_quad(rect_, bgcolor_)) addDrawable(build_quad(Rect(rect_.x0 + 4, rect_.y1 - 24, rect_.x1 - 4, rect_.y1 - 4), osg.Vec4(0, 0, 0, bgcolor_.w()), False, zPos)) caption_text = osgText.Text() caption_text.setText(caption_) caption_text.setColor(osg.Vec4(1, 1, 1, 1)) caption_text.setAlignment(osgText.Text.CENTER_CENTER) caption_text.setFont("fonts/arial.ttf") caption_text.setCharacterSize(16) caption_text.setFontResolution(16, 16) caption_text.setPosition(osg.Vec3((rect_.x0 + rect_.x1) / 2, rect_.y1 - 15, zPos*2.0)) addDrawable(caption_text) rebuild_client_area(Rect(rect_.x0 + 4, rect_.y0 + 4, rect_.x1 - 4, rect_.y1 - 28)) osg.Geometry *Frame.build_quad( Rect rect, osg.Vec4 color, bool shadow, float z) shadow_space = 8 shadow_size = 10
def main(argv): arguments = osg.ArgumentParser(argv) viewer = osgViewer.Viewer(arguments) fontFile = str("arial.ttf") while arguments.read("-f",fontFile) : font = osgText.readFontFile(fontFile) if not font : return 1 OSG_NOTICE, "Read font ", fontFile, " font=", font word = str("This is a test.")() while arguments.read("-w",word) : style = osgText.Style() thickness = 0.1 while arguments.read("--thickness",thickness) : style.setThicknessRatio(thickness) # set up any bevel if required r = float() bevel = osgText.Bevel() while arguments.read("--rounded",r) : bevel = osgText.Bevel() bevel.roundedBevel2(r) while arguments.read("--rounded") : bevel = osgText.Bevel() bevel.roundedBevel2(0.25) while arguments.read("--flat",r) : bevel = osgText.Bevel() bevel.flatBevel(r) while arguments.read("--flat") : bevel = osgText.Bevel() bevel.flatBevel(0.25) while arguments.read("--bevel-thickness",r) : if bevel.valid() : bevel.setBevelThickness(r) style.setBevel(bevel) # set up outline. while arguments.read("--outline",r) : style.setOutlineRatio(r) viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) ) viewer.addEventHandler(osgViewer.StatsHandler)() #if 1 group = osg.Group() characterSize = 1.0 while arguments.read("--size",characterSize) : if arguments.read("--2d") : text2D = osgText.Text() text2D.setFont(font) text2D.setCharacterSize(characterSize) text2D.setFontResolution(256,256) text2D.setDrawMode(osgText.Text.TEXT | osgText.Text.BOUNDINGBOX) text2D.setAxisAlignment(osgText.Text.XZ_PLANE) text2D.setText(word) geode = osg.Geode() geode.addDrawable(text2D) group.addChild(geode) if arguments.read("--TextNode") : # experimental text node text = osgText.TextNode() text.setFont(font) text.setStyle(style) text.setTextTechnique(osgText.TextTechnique)() text.setText(word) text.update() group.addChild(text) elif not arguments.read("--no-3d") : text3D = osgText.Text3D() text3D.setFont(font) text3D.setStyle(style) text3D.setCharacterSize(characterSize) text3D.setDrawMode(osgText.Text3D.TEXT | osgText.Text3D.BOUNDINGBOX) text3D.setAxisAlignment(osgText.Text3D.XZ_PLANE) text3D.setText(word) geode = osg.Geode() geode.addDrawable(text3D) group.addChild(geode) color = osg.Vec4(1.0, 1.0, 1.0, 1.0) while arguments.read("--color",color.r(),color.g(),color.b(),color.a()) : OSG_NOTICE, "--color ", color text3D.setColor(color) imageFilename = str() while arguments.read("--image",imageFilename) : OSG_NOTICE, "--image ", imageFilename image = osgDB.readImageFile(imageFilename) if image.valid() : OSG_NOTICE, " loaded image ", imageFilename stateset = text3D.getOrCreateStateSet() stateset.setTextureAttributeAndModes(0, osg.Texture2D(image), osg.StateAttribute.ON) while arguments.read("--wall-color",color.r(),color.g(),color.b(),color.a()) : stateset = text3D.getOrCreateWallStateSet() material = osg.Material() material.setDiffuse(osg.Material.FRONT_AND_BACK, color) stateset.setAttribute(material) while arguments.read("--wall-image",imageFilename) : image = osgDB.readImageFile(imageFilename) if image.valid() : stateset = text3D.getOrCreateWallStateSet() stateset.setTextureAttributeAndModes(0, osg.Texture2D(image), osg.StateAttribute.ON) while arguments.read("--back-color",color.r(),color.g(),color.b(),color.a()) : stateset = text3D.getOrCreateBackStateSet() material = osg.Material() material.setDiffuse(osg.Material.FRONT_AND_BACK, color) stateset.setAttribute(material) while arguments.read("--back-image",imageFilename) : image = osgDB.readImageFile(imageFilename) if image.valid() : stateset = text3D.getOrCreateBackStateSet() stateset.setTextureAttributeAndModes(0, osg.Texture2D(image), osg.StateAttribute.ON) if arguments.read("--size-quad") : geode.addDrawable( osg.createTexturedQuadGeometry(osg.Vec3(0.0,characterSize*thickness,0.0),osg.Vec3(characterSize,0.0,0.0),osg.Vec3(0.0,0.0,characterSize), 0.0, 0.0, 1.0, 1.0) ) viewer.setSceneData(group) #endif return viewer.run() # Translated from file 'osgtext3D_orig.cpp' # OpenSceneGraph example, osgtext. #* #* Permission is hereby granted, free of charge, to any person obtaining a copy #* of this software and associated documentation files (the "Software"), to deal #* in the Software without restriction, including without limitation the rights #* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell #* copies of the Software, and to permit persons to whom the Software is #* furnished to do so, subject to the following conditions: #* #* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR #* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, #* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE #* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER #* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, #* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN #* THE SOFTWARE. # #include <osgViewer/Viewer> #include <osgViewer/ViewerEventHandlers> #include <osgDB/ReadFile> #include <osgGA/TrackballManipulator> #include <osgGA/StateSetManipulator> #include <osg/Geode> #include <osg/Geometry> #include <osg/Material> #include <osg/Shape> #include <osg/ShapeDrawable> #include <osgText/Text3D> #include <iostream> #include <sstream> # create text which sits in 3D space such as would be inserted into a normal model def create3DText(center, radius): geode = osg.Geode() #################################################### # # Examples of how to set up axis/orientation alignments # characterSize = radius*0.2 characterDepth = characterSize*0.2 pos = osg.Vec3(center.x()-radius*.5,center.y()-radius*.5,center.z()-radius*.5) text1 = osgText.Text3D() text1.setFont("fonts/arial.ttf") text1.setCharacterSize(characterSize) text1.setCharacterDepth(characterDepth) text1.setPosition(pos) text1.setDrawMode(osgText.Text3D.TEXT | osgText.Text3D.BOUNDINGBOX) text1.setAxisAlignment(osgText.Text3D.XY_PLANE) text1.setText("XY_PLANE") geode.addDrawable(text1) text2 = osgText.Text3D() text2.setFont("fonts/times.ttf") text2.setCharacterSize(characterSize) text2.setCharacterDepth(characterDepth) text2.setPosition(pos) text2.setDrawMode(osgText.Text3D.TEXT | osgText.Text3D.BOUNDINGBOX) text2.setAxisAlignment(osgText.Text3D.YZ_PLANE) text2.setText("YZ_PLANE") geode.addDrawable(text2) text3 = osgText.Text3D() text3.setFont("fonts/dirtydoz.ttf") text3.setCharacterSize(characterSize) text3.setCharacterDepth(characterDepth) text3.setPosition(pos) text3.setDrawMode(osgText.Text3D.TEXT | osgText.Text3D.BOUNDINGBOX) text3.setAxisAlignment(osgText.Text3D.XZ_PLANE) text3.setText("XZ_PLANE") geode.addDrawable(text3) style = osgText.Style() bevel = osgText.Bevel() bevel.roundedBevel2(0.25) style.setBevel(bevel) style.setWidthRatio(0.4) text7 = osgText.Text3D() text7.setFont("fonts/times.ttf") text7.setStyle(style) text7.setCharacterSize(characterSize) text7.setCharacterDepth(characterSize*0.2) text7.setPosition(center - osg.Vec3(0.0, 0.0, 0.6)) text7.setDrawMode(osgText.Text3D.TEXT | osgText.Text3D.BOUNDINGBOX) text7.setAxisAlignment(osgText.Text3D.SCREEN) text7.setCharacterSizeMode(osgText.Text3D.OBJECT_COORDS) text7.setText("CharacterSizeMode OBJECT_COORDS (default)") geode.addDrawable(text7) shape = osg.ShapeDrawable(osg.Sphere(center,characterSize*0.2)) shape.getOrCreateStateSet().setMode(GL_LIGHTING,osg.StateAttribute.ON) geode.addDrawable(shape) rootNode = osg.Group() rootNode.addChild(geode) front = osg.Material() front.setAlpha(osg.Material.FRONT_AND_BACK,1) front.setAmbient(osg.Material.FRONT_AND_BACK,osg.Vec4(0.2,0.2,0.2,1.0)) front.setDiffuse(osg.Material.FRONT_AND_BACK,osg.Vec4(.0,.0,1.0,1.0)) rootNode.getOrCreateStateSet().setAttributeAndModes(front) return rootNode int main_orig(int, char**) viewer = osgViewer.Viewer() center = osg.Vec3(0.0,0.0,0.0) radius = 1.0 root = osg.Group() root.addChild(create3DText(center, radius)) viewer.setSceneData(root) viewer.setCameraManipulator(osgGA.TrackballManipulator()) viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) ) viewer.addEventHandler(osgViewer.ThreadingHandler)() viewer.addEventHandler(osgViewer.WindowSizeHandler)() viewer.addEventHandler(osgViewer.StatsHandler)() viewer.run() return 0 # Translated from file 'osgtext3D_test.cpp' #include <osgViewer/Viewer> #include <osgViewer/ViewerEventHandlers> #include <osgDB/ReadFile> #include <osgGA/TrackballManipulator> #include <osgGA/StateSetManipulator> #include <osg/Geode> #include <osg/Geometry> #include <osg/Material> #include <osg/Shape> #include <osg/ShapeDrawable> #include <osgText/Text3D> #include <iostream> #include <sstream> def test_create3DText(center, radius): geode = osg.Geode() characterSize = radius*0.2 characterDepth = characterSize*0.2 pos = osg.Vec3(center.x()-radius*.5,center.y()-radius*.5,center.z()-radius*.5) #define SHOW_INTESECTION_CEASH #ifdef SHOW_INTESECTION_CEASH text3 = osgText.Text3D() text3.setFont("fonts/dirtydoz.ttf") text3.setCharacterSize(characterSize) text3.setCharacterDepth(characterDepth) text3.setPosition(pos) text3.setDrawMode(osgText.Text3D.TEXT | osgText.Text3D.BOUNDINGBOX) text3.setAxisAlignment(osgText.Text3D.XZ_PLANE) text3.setText("CRAS H") #intersection crash geode.addDrawable(text3) #else: text7 = osgText.Text3D() text7.setFont("fonts/times.ttf") text7.setCharacterSize(characterSize) text7.setCharacterDepth(characterSize*2.2) text7.setPosition(center - osg.Vec3(0.0, 0.0, 0.6)) text7.setDrawMode(osgText.Text3D.TEXT | osgText.Text3D.BOUNDINGBOX) text7.setAxisAlignment(osgText.Text3D.SCREEN) text7.setCharacterSizeMode(osgText.Text3D.OBJECT_COORDS) text7.setText("ABCDE") #wrong intersection geode.addDrawable(text7) #endif shape = osg.ShapeDrawable(osg.Sphere(center,characterSize*0.2)) shape.getOrCreateStateSet().setMode(GL_LIGHTING,osg.StateAttribute.ON) geode.addDrawable(shape) rootNode = osg.Group() rootNode.addChild(geode) #define SHOW_WRONG_NORMAL #ifdef SHOW_WRONG_NORMAL front = osg.Material() # front.setAlpha(osg.Material.FRONT_AND_BACK,1) front.setAmbient(osg.Material.FRONT_AND_BACK,osg.Vec4(0.2,0.2,0.2,1.0)) front.setDiffuse(osg.Material.FRONT_AND_BACK,osg.Vec4(.0,.0,1.0,1.0)) rootNode.getOrCreateStateSet().setAttributeAndModes(front) #else: stateset = osg.StateSet() #Show wireframe polymode = osg.PolygonMode() polymode.setMode(osg.PolygonMode.FRONT_AND_BACK,osg.PolygonMode.LINE) stateset.setAttributeAndModes(polymode,osg.StateAttribute.OVERRIDE|osg.StateAttribute.ON) rootNode.setStateSet(stateset) #endif return rootNode ##################################### #include <osg/PositionAttitudeTransform> #include <osg/ShapeDrawable> class CInputHandler (osgGA.GUIEventHandler) : CInputHandler( osg.PositionAttitudeTransform* pPatSphere ) m_rPatSphere = pPatSphere def handle(ea, aa, pObject, pNodeVisitor): pViewer = dynamic_cast<osgViewer.Viewer*>(aa) if not pViewer : return False if ea.getEventType()==osgGA.GUIEventAdapter.PUSH : cams = osgViewer.ViewerBase.Cameras() pViewer.getCameras( cams ) x = ea.getXnormalized() y = ea.getYnormalized() picker = osgUtil.LineSegmentIntersector( osgUtil.Intersector.PROJECTION, x, y ) iv = osgUtil.IntersectionVisitor( picker ) cams[0].accept( iv ) if picker.containsIntersections() : intersection = picker.getFirstIntersection() v = intersection.getWorldIntersectPoint() m_rPatSphere.setPosition( v ) return True # return True, event handled return False m_rPatSphere = osg.PositionAttitudeTransform() ##################################### int main_test(int, char**) viewer = osgViewer.Viewer() viewer.setUpViewInWindow(99,99,666,666, 0) rPat = osg.PositionAttitudeTransform() # add the handler to the viewer viewer.addEventHandler( CInputHandler(rPat) ) # create a group to contain our scene and sphere pGroup = osg.Group() # create sphere pGeodeSphere = osg.Geode() pGeodeSphere.addDrawable( osg.ShapeDrawable( osg.Sphere(osg.Vec3(0.0,0.0,0.0),0.01) ) ) rPat.addChild( pGeodeSphere ) pGroup.addChild( rPat ) center = osg.Vec3(0.0,0.0,0.0) radius = 1.0 root = osg.Group() root.addChild(test_create3DText(center, radius)) #viewer.setSceneData(root) pGroup.addChild(root) viewer.setSceneData(pGroup) viewer.setCameraManipulator(osgGA.TrackballManipulator()) viewer.addEventHandler( osgGA.StateSetManipulator(viewer.getCamera().getOrCreateStateSet()) ) viewer.addEventHandler(osgViewer.ThreadingHandler)() viewer.addEventHandler(osgViewer.WindowSizeHandler)() viewer.addEventHandler(osgViewer.StatsHandler)() return viewer.run() # Translated from file 'TextNode.cpp' # -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield # * # * This library is open source and may be redistributed and/or modified under # * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or # * (at your option) any later version. The full license is in LICENSE file # * included with this distribution, and on the openscenegraph.org website. # * # * This library 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. See the # * OpenSceneGraph Public License for more details. # #include "TextNode.h" #include "../../src/osgText/GlyphGeometry.h" #include <osg/PositionAttitudeTransform> #include <osg/Geode> #include <osgUtil/SmoothingVisitor> #include <osg/io_utils> using namespace osgText ############################################/ # # Layout # Layout.Layout() Layout.Layout( Layout layout, osg.CopyOp copyop): osg.Object(layout,copyop)
class IntersectionUpdateCallback (osg.NodeCallback) : virtual void operator()(osg.Node* #node, osg.NodeVisitor* nv) if not root_ or not terrain_ or not ss_ or not intersectionGroup_ : osg.notify(osg.NOTICE), "IntersectionUpdateCallback not set up correctly." return #traverse(node,nv) frameCount_++ if frameCount_ > 200 : # first we need find the transformation matrix that takes # the terrain into the coordinate frame of the sphere segment. terrainLocalToWorld = osg.Matrixd() terrain_worldMatrices = terrain_.getWorldMatrices(root_) if terrain_worldMatrices.empty() : terrainLocalToWorld.makeIdentity() elif terrain_worldMatrices.size()==1 : terrainLocalToWorld = terrain_worldMatrices.front() else: osg.notify(osg.NOTICE), "IntersectionUpdateCallback: warning cannot interestect with multiple terrain instances, just uses first one." terrainLocalToWorld = terrain_worldMatrices.front() # sphere segment is easier as this callback is attached to the node, so the node visitor has the unique path to it already. ssWorldToLocal = osg.computeWorldToLocal(nv.getNodePath()) # now we can compute the terrain to ss transform possie = terrainLocalToWorld*ssWorldToLocal lines = ss_.computeIntersection(possie, terrain_) if not lines.empty() : if intersectionGroup_.valid() : # now we need to place the intersections which are in the SphereSegmenet's coordinate frame into # to the final position. mt = osg.MatrixTransform() mt.setMatrix(osg.computeLocalToWorld(nv.getNodePath())) intersectionGroup_.addChild(mt) # print "matrix = ", mt.getMatrix() geode = osg.Geode() mt.addChild(geode) geode.getOrCreateStateSet().setMode(GL_LIGHTING,osg.StateAttribute.OFF) for(osgSim.SphereSegment.LineList.iterator itr=lines.begin() not = lines.end() ++itr) geom = osg.Geometry() geode.addDrawable(geom) vertices = itr geom.setVertexArray(vertices) geom.addPrimitiveSet(osg.DrawArrays(GL_LINE_STRIP, 0, vertices.getNumElements())) else: osg.notify(osg.NOTICE), "No intersections found" frameCount_ = 0 root_ = osg.observer_ptr<osg.Group>() terrain_ = osg.observer_ptr<osg.Geode>() ss_ = osg.observer_ptr<osgSim.SphereSegment>() intersectionGroup_ = osg.observer_ptr<osg.Group>() frameCount_ = unsigned() class RotateUpdateCallback (osg.NodeCallback) : RotateUpdateCallback() i=0 virtual void operator()(osg.Node* node, osg.NodeVisitor* nv) ss = dynamic_cast<osgSim.SphereSegment *>(node) if ss : ss.setArea(osg.Vec3(cos(i/(2*osg.PI)),sin(i/(2*osg.PI)),0), osg.PI_2, osg.PI_2) i += 0.1 i = float() def createMovingModel(center, radius, terrainGeode, root, createMovingRadar): animationLength = 10.0 animationPath = createAnimationPath(center,radius,animationLength) model = osg.Group() glider = osgDB.readNodeFile("glider.osgt") if glider : bs = glider.getBound() size = radius/bs.radius()*0.3 positioned = osg.MatrixTransform() positioned.setDataVariance(osg.Object.STATIC) positioned.setMatrix(osg.Matrix.translate(-bs.center())* osg.Matrix.scale(size,size,size)* osg.Matrix.rotate(osg.inDegrees(-90.0),0.0,0.0,1.0)) positioned.addChild(glider) xform = osg.PositionAttitudeTransform() xform.getOrCreateStateSet().setMode(GL_NORMALIZE, osg.StateAttribute.ON) xform.setUpdateCallback(osg.AnimationPathCallback(animationPath,0.0,1.0)) xform.addChild(positioned) model.addChild(xform) if createMovingRadar : # The IntersectionUpdateCallback has to have a safe place to put all its generated geometry into, # and this group can't be in the parental chain of the callback otherwise we will end up invalidating # traversal iterators. intersectionGroup = osg.Group() root.addChild(intersectionGroup) xform = osg.PositionAttitudeTransform() xform.setUpdateCallback(osg.AnimationPathCallback(animationPath,0.0,1.0)) ss = osgSim.SphereSegment(osg.Vec3d(0.0,0.0,0.0), 700.0, # radius osg.DegreesToRadians(135.0), osg.DegreesToRadians(240.0), osg.DegreesToRadians(-60.0), osg.DegreesToRadians(-40.0), 60) iuc = IntersectionUpdateCallback() iuc.frameCount_ = 0 iuc.root_ = root iuc.terrain_ = terrainGeode iuc.ss_ = ss iuc.intersectionGroup_ = intersectionGroup ss.setUpdateCallback(iuc) ss.setAllColors(osg.Vec4(1.0,1.0,1.0,0.5)) ss.setSideColor(osg.Vec4(0.5,1.0,1.0,0.1)) xform.addChild(ss) model.addChild(xform) cessna = osgDB.readNodeFile("cessna.osgt") if cessna : bs = cessna.getBound() text = osgText.Text() size = radius/bs.radius()*0.3 text.setPosition(bs.center()) text.setText("Cessna") text.setAlignment(osgText.Text.CENTER_CENTER) text.setAxisAlignment(osgText.Text.SCREEN) text.setCharacterSize(40.0) text.setCharacterSizeMode(osgText.Text.OBJECT_COORDS) geode = osg.Geode() geode.addDrawable(text) lod = osg.LOD() lod.setRangeMode(osg.LOD.PIXEL_SIZE_ON_SCREEN) lod.setRadius(cessna.getBound().radius()) lod.addChild(geode,0.0,100.0) lod.addChild(cessna,100.0,10000.0) positioned = osg.MatrixTransform() positioned.getOrCreateStateSet().setMode(GL_NORMALIZE, osg.StateAttribute.ON) positioned.setDataVariance(osg.Object.STATIC) positioned.setMatrix(osg.Matrix.translate(-bs.center())* osg.Matrix.scale(size,size,size)* osg.Matrix.rotate(osg.inDegrees(180.0),0.0,0.0,1.0)) #positioned.addChild(cessna) positioned.addChild(lod) xform = osg.MatrixTransform() xform.setUpdateCallback(osg.AnimationPathCallback(animationPath,0.0,2.0)) xform.addChild(positioned) model.addChild(xform) return model def createOverlay(center, radius): group = osg.Group() # create a grid of lines. geom = osg.Geometry() num_rows = 10 left = center+osg.Vec3(-radius,-radius,0.0) right = center+osg.Vec3(radius,-radius,0.0) delta_row = osg.Vec3(0.0,2.0*radius/float(num_rows-1),0.0) top = center+osg.Vec3(-radius,radius,0.0) bottom = center+osg.Vec3(-radius,-radius,0.0) delta_column = osg.Vec3(2.0*radius/float(num_rows-1),0.0,0.0) vertices = osg.Vec3Array() for(unsigned int i=0 i<num_rows ++i) vertices.push_back(left) vertices.push_back(right) left += delta_row right += delta_row vertices.push_back(top) vertices.push_back(bottom) top += delta_column bottom += delta_column geom.setVertexArray(vertices) color = *(osg.Vec4ubArray(1)) color[0].set(0,0,0,255) geom.setColorArray(color, osg.Array.BIND_OVERALL) geom.addPrimitiveSet(osg.DrawArrays(GL_LINES,0,vertices.getNumElements())) geom.getOrCreateStateSet().setMode(GL_LIGHTING,osg.StateAttribute.OFF) geode = osg.Geode() geode.addDrawable(geom) group.addChild(geode) return group def computeTerrainIntersection(subgraph, x, y): bs = subgraph.getBound() zMax = bs.center().z()+bs.radius() zMin = bs.center().z()-bs.radius() intersector = osgUtil.LineSegmentIntersector(osg.Vec3(x,y,zMin),osg.Vec3(x,y,zMax)) iv = osgUtil.IntersectionVisitor(intersector) subgraph.accept(iv) if intersector.containsIntersections() : return intersector.getFirstIntersection().getWorldIntersectPoint() return osg.Vec3(x,y,0.0) ####################################### # MAIN SCENE GRAPH BUILDING FUNCTION ####################################### def build_world(root, testCase, useOverlay, technique): # create terrain terrainGeode = 0 terrainGeode = osg.Geode() stateset = osg.StateSet() image = osgDB.readImageFile("Images/lz.rgb") if image : texture = osg.Texture2D() texture.setImage(image) stateset.setTextureAttributeAndModes(0,texture,osg.StateAttribute.ON) terrainGeode.setStateSet( stateset ) numColumns = 38 numRows = 39 unsigned int r, c origin = osg.Vec3(0.0,0.0,0.0) size = osg.Vec3(1000.0,1000.0,250.0) geometry = osg.Geometry() v = *(osg.Vec3Array(numColumns*numRows)) tc = *(osg.Vec2Array(numColumns*numRows)) color = *(osg.Vec4ubArray(1)) color[0].set(255,255,255,255) rowCoordDelta = size.y()/(float)(numRows-1) columnCoordDelta = size.x()/(float)(numColumns-1) rowTexDelta = 1.0/(float)(numRows-1) columnTexDelta = 1.0/(float)(numColumns-1) # compute z range of z values of grid data so we can scale it. min_z = FLT_MAX max_z = -FLT_MAX for(r=0r<numRows++r) for(c=0c<numColumns++c) min_z = osg.minimum(min_z,vertex[r+c*numRows][2]) max_z = osg.maximum(max_z,vertex[r+c*numRows][2]) scale_z = size.z()/(max_z-min_z) pos = origin tex = osg.Vec2(0.0,0.0) vi = 0 for(r=0r<numRows++r) pos.x() = origin.x() tex.x() = 0.0 for(c=0c<numColumns++c) v[vi].set(pos.x(),pos.y(),pos.z()+(vertex[r+c*numRows][2]-min_z)*scale_z) tc[vi] = tex pos.x()+=columnCoordDelta tex.x()+=columnTexDelta ++vi pos.y() += rowCoordDelta tex.y() += rowTexDelta geometry.setVertexArray(v) geometry.setTexCoordArray(0, tc) geometry.setColorArray(color, osg.Array.BIND_OVERALL) for(r=0r<numRows-1++r) drawElements = *(osg.DrawElementsUShort(GL_QUAD_STRIP,2*numColumns)) geometry.addPrimitiveSet(drawElements) ei = 0 for(c=0c<numColumns++c) drawElements[ei++] = (r+1)*numColumns+c drawElements[ei++] = (r)*numColumns+c smoother = osgUtil.SmoothingVisitor() smoother.smooth(*geometry) terrainGeode.addDrawable(geometry) # create sphere segment ss = 0 terrainToSS = osg.Matrix() switch(testCase) case(0): ss = osgSim.SphereSegment( computeTerrainIntersection(terrainGeode,550.0,780.0), # center 510.0, # radius osg.DegreesToRadians(135.0), osg.DegreesToRadians(240.0), osg.DegreesToRadians(-10.0), osg.DegreesToRadians(30.0), 60) root.addChild(ss) break case(1): ss = osgSim.SphereSegment( computeTerrainIntersection(terrainGeode,550.0,780.0), # center 510.0, # radius osg.DegreesToRadians(45.0), osg.DegreesToRadians(240.0), osg.DegreesToRadians(-10.0), osg.DegreesToRadians(30.0), 60) root.addChild(ss) break case(2): ss = osgSim.SphereSegment( computeTerrainIntersection(terrainGeode,550.0,780.0), # center 510.0, # radius osg.DegreesToRadians(5.0), osg.DegreesToRadians(355.0), osg.DegreesToRadians(-10.0), osg.DegreesToRadians(30.0), 60) root.addChild(ss) break case(3): ss = osgSim.SphereSegment( computeTerrainIntersection(terrainGeode,550.0,780.0), # center 510.0, # radius osg.DegreesToRadians(0.0), osg.DegreesToRadians(360.0), osg.DegreesToRadians(-10.0), osg.DegreesToRadians(30.0), 60) root.addChild(ss) break case(4): ss = osgSim.SphereSegment(osg.Vec3d(0.0,0.0,0.0), 700.0, # radius osg.DegreesToRadians(135.0), osg.DegreesToRadians(240.0), osg.DegreesToRadians(-60.0), osg.DegreesToRadians(-40.0), 60) mt = osg.MatrixTransform() mt.setMatrix(osg.Matrix(-0.851781, 0.156428, -0.5, 0, -0.180627, -0.983552, -6.93889e-18, 0, -0.491776, 0.0903136, 0.866025, 0, 598.217, 481.957, 100, 1)) mt.addChild(ss) terrainToSS.invert(mt.getMatrix()) root.addChild(mt) break case(5): ss = osgSim.SphereSegment(osg.Vec3d(0.0,0.0,0.0), 700.0, # radius osg.DegreesToRadians(35.0), osg.DegreesToRadians(135.0), osg.DegreesToRadians(-60.0), osg.DegreesToRadians(-40.0), 60) mt = osg.MatrixTransform() mt.setMatrix(osg.Matrix(-0.851781, 0.156428, -0.5, 0, -0.180627, -0.983552, -6.93889e-18, 0, -0.491776, 0.0903136, 0.866025, 0, 598.217, 481.957, 100, 1)) mt.addChild(ss) terrainToSS.invert(mt.getMatrix()) root.addChild(mt) break case(6): ss = osgSim.SphereSegment(osg.Vec3d(0.0,0.0,0.0), 700.0, # radius osg.DegreesToRadians(-45.0), osg.DegreesToRadians(45.0), osg.DegreesToRadians(-60.0), osg.DegreesToRadians(-40.0), 60) mt = osg.MatrixTransform() mt.setMatrix(osg.Matrix(-0.851781, 0.156428, -0.5, 0, -0.180627, -0.983552, -6.93889e-18, 0, -0.491776, 0.0903136, 0.866025, 0, 598.217, 481.957, 100, 1)) mt.addChild(ss) terrainToSS.invert(mt.getMatrix()) root.addChild(mt) break case(7): ss = osgSim.SphereSegment( computeTerrainIntersection(terrainGeode,550.0,780.0), # center 510.0, # radius osg.DegreesToRadians(-240.0), osg.DegreesToRadians(-135.0), osg.DegreesToRadians(-10.0), osg.DegreesToRadians(30.0), 60) ss.setUpdateCallback(RotateUpdateCallback()) root.addChild(ss) break if ss.valid() : ss.setAllColors(osg.Vec4(1.0,1.0,1.0,0.5)) ss.setSideColor(osg.Vec4(0.0,1.0,1.0,0.1)) if not ss.getParents().empty() : ss.getParent(0).addChild(ss.computeIntersectionSubgraph(terrainToSS, terrainGeode)) if useOverlay : overlayNode = osgSim.OverlayNode(technique) overlayNode.getOrCreateStateSet().setTextureAttribute(1, osg.TexEnv(osg.TexEnv.DECAL)) bs = terrainGeode.getBound() overlaySubgraph = createOverlay(bs.center(), bs.radius()*0.5) overlaySubgraph.addChild(ss) overlayNode.setOverlaySubgraph(overlaySubgraph) overlayNode.setOverlayTextureSizeHint(1024) overlayNode.setOverlayBaseHeight(0.0) overlayNode.addChild(terrainGeode) root.addChild(overlayNode) else: root.addChild(terrainGeode) # create particle effects position = computeTerrainIntersection(terrainGeode,100.0,100.0) explosion = osgParticle.ExplosionEffect(position, 10.0) smoke = osgParticle.SmokeEffect(position, 10.0) fire = osgParticle.FireEffect(position, 10.0) root.addChild(explosion) root.addChild(smoke) root.addChild(fire) # create particle effects position = computeTerrainIntersection(terrainGeode,200.0,100.0) explosion = osgParticle.ExplosionEffect(position, 1.0) smoke = osgParticle.SmokeEffect(position, 1.0) fire = osgParticle.FireEffect(position, 1.0) root.addChild(explosion) root.addChild(smoke) root.addChild(fire) createMovingRadar = True # create the moving models. root.addChild(createMovingModel(osg.Vec3(500.0,500.0,500.0),100.0, terrainGeode, root, createMovingRadar)) ####################################### # main() ####################################### def main(argv): # use an ArgumentParser object to manage the program arguments. arguments = osg.ArgumentParser(argv) # set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage().setDescription(arguments.getApplicationName()+" is the example which demonstrates use of particle systems.") arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] image_file_left_eye image_file_right_eye") arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display this information") # construct the viewer. viewer = osgViewer.Viewer(arguments) # if user request help write it out to cout. testCase = 0 while arguments.read("-t", testCase) : useOverlay = False technique = osgSim.OverlayNode.OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY while arguments.read("--object") : useOverlay = True technique = osgSim.OverlayNode.OBJECT_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY while arguments.read("--ortho") or arguments.read("--orthographic") : useOverlay = True technique = osgSim.OverlayNode.VIEW_DEPENDENT_WITH_ORTHOGRAPHIC_OVERLAY while arguments.read("--persp") or arguments.read("--perspective") : useOverlay = True technique = osgSim.OverlayNode.VIEW_DEPENDENT_WITH_PERSPECTIVE_OVERLAY # if user request help write it out to cout. if arguments.read("-h") or arguments.read("--help") : arguments.getApplicationUsage().write(std.cout) return 1 # any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized() # report any errors if they have occurred when parsing the program arguments. if arguments.errors() : arguments.writeErrorMessages(std.cout) return 1 root = osg.Group() build_world(root, testCase, useOverlay, technique) # add a viewport to the viewer and attach the scene graph. viewer.setSceneData(root) return viewer.run() if __name__ == "__main__": main(sys.argv)
def main(argv): # use an ArgumentParser object to manage the program arguments. arguments = osg.ArgumentParser(argv) arguments.getApplicationUsage().addCommandLineOption("--zeroconf","uses zeroconf to advertise the osc-plugin and to discover it") arguments.getApplicationUsage().addCommandLineOption("--sender","create a view which sends its events via osc") arguments.getApplicationUsage().addCommandLineOption("--recevier","create a view which receive its events via osc") # read the scene from the list of file specified commandline args. scene = osgDB.readNodeFiles(arguments) if not scene : print argv[0], ": requires filename argument." return 1 use_zeroconf = bool(False) use_sender = bool(False) use_receiver = bool(False) if arguments.find("--zeroconf") > 0 : use_zeroconf = True if arguments.find("--sender") > 0 : use_sender = True if arguments.find("--receiver") > 0 : use_receiver = True # construct the viewer. viewer = osgViewer.CompositeViewer(arguments) # receiver view if use_receiver : traits = osg.GraphicsContext.Traits() traits.x = 600 traits.y = 100 traits.width = 400 traits.height = 400 traits.windowDecoration = True traits.doubleBuffer = True traits.sharedContext = 0 traits.windowName = "Receiver / view two" gc = osg.GraphicsContext.createGraphicsContext(traits) view = osgViewer.View() view.setName("View two") viewer.addView(view) group = osg.Group() group.addChild(scene) geode = osg.Geode() group.addChild(geode) text = osgText.Text() geode.addDrawable( text ) text.setFont("Arial.ttf") text.setText("Waiting for data") text.setPosition(osg.Vec3(-50,0,30)) text.setAxisAlignment(osgText.TextBase.SCREEN) text.setDataVariance(osg.Object.DYNAMIC) text.setCharacterSize(2.0) view.setSceneData(group) view.getCamera().setName("Cam two") view.getCamera().setViewport(osg.Viewport(0,0, traits.width, traits.height)) view.getCamera().setGraphicsContext(gc) view.addEventHandler( osgViewer.StatsHandler )() view.addEventHandler( UserEventHandler(text) ) device = osgDB.readFile<osgGA.Device>("0.0.0.0:9000.receiver.osc") if device.valid() and (device.getCapabilities() osgGA.Device.RECEIVE_EVENTS) : view.addDevice(device) # add a zeroconf device, advertising the osc-device if use_zeroconf : zeroconf_device = osgDB.readFile<osgGA.Device>("_osc._udp:9000.advertise.zeroconf") if zeroconf_device : view.addDevice(zeroconf_device) else: OSG_WARN, "could not open osc-device, receiving will not work"
_inputText.getText().push_back(key) _inputText.update() elif key==osgGA.GUIEventAdapter.KEY_Return : _inputText.getText().push_back('\n') _inputText.update() elif key==osgGA.GUIEventAdapter.KEY_BackSpace or key==osgGA.GUIEventAdapter.KEY_Delete : if not _inputText.getText().empty() : _inputText.getText().pop_back() _inputText.update() osg.Switch* KeyboardModel.addKey(osg.Vec3 pos, int key, str text,float width, float height) geodeUp = osg.Geode() textUp = osgText.Text() textUp.setFont("fonts/arial.ttf") textUp.setColor(osg.Vec4(1.0,1.0,1.0,1.0)) textUp.setCharacterSize(height) textUp.setPosition(pos) textUp.setDrawMode(osgText.Text.TEXT#|osgText.Text.BOUNDINGBOX) textUp.setAlignment(osgText.Text.LEFT_CENTER) textUp.setAxisAlignment(osgText.Text.XZ_PLANE) textUp.setText(text) geodeUp.addDrawable(textUp) geodeDown = osg.Geode() textDown = osgText.Text() textDown.setFont("fonts/arial.ttf") textDown.setColor(osg.Vec4(1.0,0.0,1.0,1.0))
def createHUD(): # create a camera to set up the projection and model view matrices, and the subgraph to draw in the HUD camera = osg.Camera() # set the projection matrix camera.setProjectionMatrix(osg.Matrix.ortho2D(0,1280,0,1024)) # set the view matrix camera.setReferenceFrame(osg.Transform.ABSOLUTE_RF) camera.setViewMatrix(osg.Matrix.identity()) # only clear the depth buffer camera.setClearMask(GL_DEPTH_BUFFER_BIT) # draw subgraph after main camera view. camera.setRenderOrder(osg.Camera.POST_RENDER) # we don't want the camera to grab event focus from the viewers main camera(s). camera.setAllowEventFocus(False) # add to this camera a subgraph to render geode = osg.Geode() timesFont = str("fonts/arial.ttf") # turn lighting off for the text and disable depth test to ensure it's always ontop. stateset = geode.getOrCreateStateSet() stateset.setMode(GL_LIGHTING,osg.StateAttribute.OFF) position = osg.Vec3(150.0,800.0,0.0) delta = osg.Vec3(0.0,-120.0,0.0) text = osgText.Text() geode.addDrawable( text ) text.setFont(timesFont) text.setPosition(position) text.setText("Head Up Displays are simple :-)") position += delta text = osgText.Text() geode.addDrawable( text ) text.setFont(timesFont) text.setPosition(position) text.setText("All you need to do is create your text in a subgraph.") position += delta text = osgText.Text() geode.addDrawable( text ) text.setFont(timesFont) text.setPosition(position) text.setText("Then place an osg.Camera above the subgraph\n" "to create an orthographic projection.\n") position += delta text = osgText.Text() geode.addDrawable( text ) text.setFont(timesFont) text.setPosition(position) text.setText("Set the Camera's ReferenceFrame to ABSOLUTE_RF to ensure\n" "it remains independent from any external model view matrices.") position += delta text = osgText.Text() geode.addDrawable( text ) text.setFont(timesFont) text.setPosition(position) text.setText("And set the Camera's clear mask to just clear the depth buffer.") position += delta text = osgText.Text() geode.addDrawable( text ) text.setFont(timesFont) text.setPosition(position) text.setText("And finally set the Camera's RenderOrder to POST_RENDER\n" "to make sure it's drawn last.") position += delta bb = osg.BoundingBox() for(unsigned int i=0i<geode.getNumDrawables()++i) bb.expandBy(geode.getDrawable(i).getBound())
_initialNumDropsPerSecond = float() _gameSwitch = osg.Switch() _gameGroup = osg.Group() _levelSwitch = osg.Switch() _currentIndex = unsigned int() _welcomeIndex = unsigned int() _lostIndex = unsigned int() _wonIndex = unsigned int() _gameIndex = unsigned int() _levelStartTick = osg.Timer_t() _currentScore = unsigned int() _levelText = osgText.Text() _scoreTextList = TextList() _numberOfPlayers = unsigned int() Character _players[2] typedef std.list< CatchableObject > CatchableObjectList _catchableObjects = CatchableObjectList() _backgroundFiles = FileList() _benignCatachables = FileList() _leftKeyPressed = bool() _rightKeyPressed = bool() _dummyCatchable = CatchableObject()