def createAxis(previousJoint): height = 12.0 radius = .5 zmt = osg.MatrixTransform() previousJoint.addChild(zmt) zShape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints) zCone = osg.ShapeDrawable(osg.Cone(osg.Vec3(0.0,0.0,1.0),radius+1.0,2.0),hints) zmtCone = osg.MatrixTransform() zgCone = osg.Geode() zmtCone.setMatrix( osg.Matrix.translate(0.0,0.0,height)) previousJoint.addChild(zmtCone) zShape.setColor(osg.Vec4(0.0, 0.0, 1.0, 1.0)) zCone.setColor(osg.Vec4(0.0, 0.0, 1.0, 1.0)) z = osg.Geode() z.addDrawable(zShape) zgCone.addDrawable(zCone) zmtCone.addChild(zgCone) zmt.addChild(z) mt = osg.MatrixTransform() previousJoint.addChild(mt) xMatrix = osg.Matrix.rotate(-osg.PI_2, 0.0, 1.0, 0.0) mt.setMatrix(xMatrix) xShape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints) xShape.setColor(osg.Vec4(1.0, 0.0, 0.0, 1.0)) x = osg.Geode() x.addDrawable(xShape) mt.addChild(x) yMt = osg.MatrixTransform() previousJoint.addChild(yMt) yMatrix = osg.Matrix.rotate(osg.PI_2, 1.0, 0.0, 0.0) yMt.setMatrix(yMatrix) yShape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints) yShape.setColor(osg.Vec4(0.0, 1.0, 0.0, 1.0)) y = osg.Geode() y.addDrawable(yShape) yMt.addChild(y)
def buildJoint6(previousJoint): height = 3.0 radius = 1.0 joint = osg.Geode() joint.addDrawable(osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints)) xTransform = osg.MatrixTransform() xRot = osg.Matrix.rotate(osg.PI_2, 1.0, 0.0, 0.0) xTransform.setMatrix(xRot) xTransform.addChild(joint) previousJoint.addChild(xTransform) if showAxis : createAxis(xTransform) return xTransform
def buildJoint1(previousJoint): xTransform = osg.MatrixTransform() previousJoint.addChild(xTransform) radius = 6.7640 height = 45.0 joint = osg.Geode() xTransform.addChild(joint) joint.addDrawable(osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints)) zTransform = osg.MatrixTransform() xTransform.addChild(zTransform) zTrans = osg.Matrix.translate(0.0, 0.0, height) zRot = osg.Matrix.rotate(jointAngle1, 0.0, 0.0, 1.0) zTransform.setMatrix(zTrans*zRot) return zTransform
def createShapes(): geode = osg.Geode() # --------------------------------------- # Set up a StateSet to texture the objects # --------------------------------------- stateset = osg.StateSet() image = osgDB.readImageFile( "Images/lz.rgb" ) if image : texture = osg.Texture2D() texture.setImage(image) texture.setFilter(osg.Texture.MIN_FILTER, osg.Texture.LINEAR) stateset.setTextureAttributeAndModes(0,texture, osg.StateAttribute.ON) stateset.setMode(GL_LIGHTING, osg.StateAttribute.ON) geode.setStateSet( stateset ) radius = 0.8 height = 1.0 hints = osg.TessellationHints() hints.setDetailRatio(0.5) geode.addDrawable(osg.ShapeDrawable(osg.Sphere(osg.Vec3(0.0,0.0,0.0),radius),hints)) geode.addDrawable(osg.ShapeDrawable(osg.Box(osg.Vec3(2.0,0.0,0.0),2*radius),hints)) geode.addDrawable(osg.ShapeDrawable(osg.Cone(osg.Vec3(4.0,0.0,0.0),radius,height),hints)) geode.addDrawable(osg.ShapeDrawable(osg.Cylinder(osg.Vec3(6.0,0.0,0.0),radius,height),hints)) geode.addDrawable(osg.ShapeDrawable(osg.Capsule(osg.Vec3(8.0,0.0,0.0),radius,height),hints)) grid = osg.HeightField() grid.allocate(38,39) grid.setXInterval(0.28) grid.setYInterval(0.28) for(unsigned int r=0r<39++r) for(unsigned int c=0c<38++c) grid.setHeight(c,r,vertex[r+c*39][2])
def buildJoint5(previousJoint): radius = 2.86479 height = 2.86479*2 joint = osg.Geode() shape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,0.0),radius,height),hints) joint.addDrawable(shape) xTransform = osg.MatrixTransform() previousJoint.addChild(xTransform) xRot = osg.Matrix.rotate(-osg.PI_2, 1.0,0,0) xTransform.setMatrix(xRot) xTransform.addChild(joint) if showAxis : createAxis(xTransform) zTransform = osg.MatrixTransform() zRot = osg.Matrix.rotate(jointAngle5, 0,0,1) zTrans = osg.Matrix.translate(0,0,0) zTransform.setMatrix(zTrans*zRot) xTransform.addChild(zTransform) return zTransform
def buildTube5(previousJoint): if showAxis : createAxis(previousJoint) height = 7.5 radius = 2.86479 height = 15.0 joint = osg.Geode() shape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0,0.0,height/2),radius,height),hints) joint.addDrawable(shape) xTransform = osg.MatrixTransform() previousJoint.addChild(xTransform) xTransform.addChild(joint) zTransform = osg.MatrixTransform() zTrans = osg.Matrix.translate(0,0,height) zTransform.setMatrix(zTrans) xTransform.addChild(zTransform) return zTransform
def createDemoScene(fixedSizeInScreen): root = osg.Group() geode_1 = osg.Geode() transform_1 = osg.MatrixTransform() geode_2 = osg.Geode() transform_2 = osg.MatrixTransform() geode_3 = osg.Geode() transform_3 = osg.MatrixTransform() geode_4 = osg.Geode() transform_4 = osg.MatrixTransform() geode_5 = osg.Geode() transform_5 = osg.MatrixTransform() geode_6 = osg.Geode() transform_6 = osg.MatrixTransform() geode_7 = osg.Geode() transform_7 = osg.MatrixTransform() radius = 0.8 height = 1.0 hints = osg.TessellationHints() hints.setDetailRatio(2.0) shape = osg.ShapeDrawable() shape = osg.ShapeDrawable(osg.Box(osg.Vec3(0.0, 0.0, -2.0), 10, 10.0, 0.1), hints) shape.setColor(osg.Vec4(0.5, 0.5, 0.7, 1.0)) geode_1.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0, 0.0, 0.0), radius * 2,radius), hints) shape.setColor(osg.Vec4(0.8, 0.8, 0.8, 1.0)) geode_2.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(-3.0, 0.0, 0.0), radius,radius), hints) shape.setColor(osg.Vec4(0.6, 0.8, 0.8, 1.0)) geode_3.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cone(osg.Vec3(3.0, 0.0, 0.0), 2 * radius,radius), hints) shape.setColor(osg.Vec4(0.4, 0.9, 0.3, 1.0)) geode_4.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cone(osg.Vec3(0.0, -3.0, 0.0), radius, height), hints) shape.setColor(osg.Vec4(0.2, 0.5, 0.7, 1.0)) geode_5.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cylinder(osg.Vec3(0.0, 3.0, 0.0), radius, height), hints) shape.setColor(osg.Vec4(1.0, 0.3, 0.3, 1.0)) geode_6.addDrawable(shape) shape = osg.ShapeDrawable(osg.Cone(osg.Vec3(0.0, 0.0, 3.0), 2.0, 2.0), hints) shape.setColor(osg.Vec4(0.8, 0.8, 0.4, 1.0)) geode_7.addDrawable(shape) # material matirial = osg.Material() matirial.setColorMode(osg.Material.DIFFUSE) matirial.setAmbient(osg.Material.FRONT_AND_BACK, osg.Vec4(0, 0, 0, 1)) matirial.setSpecular(osg.Material.FRONT_AND_BACK, osg.Vec4(1, 1, 1, 1)) matirial.setShininess(osg.Material.FRONT_AND_BACK, 64.0) root.getOrCreateStateSet().setAttributeAndModes(matirial, osg.StateAttribute.ON) transform_1.addChild(addDraggerToScene(geode_1,"TabBoxDragger",fixedSizeInScreen)) transform_2.addChild(addDraggerToScene(geode_2,"TabPlaneDragger",fixedSizeInScreen)) transform_3.addChild(addDraggerToScene(geode_3,"TabBoxTrackballDragger",fixedSizeInScreen)) transform_4.addChild(addDraggerToScene(geode_4,"TrackballDragger",fixedSizeInScreen)) transform_5.addChild(addDraggerToScene(geode_5,"Translate1DDragger",fixedSizeInScreen)) transform_6.addChild(addDraggerToScene(geode_6,"Translate2DDragger",fixedSizeInScreen)) transform_7.addChild(addDraggerToScene(geode_7,"TranslateAxisDragger",fixedSizeInScreen)) root.addChild(transform_1) root.addChild(transform_2) root.addChild(transform_3) root.addChild(transform_4) root.addChild(transform_5) root.addChild(transform_6) root.addChild(transform_7) return root
"\n" " gl_FragColor = clamp( color, 0.0, 1.0 )\n" "\n" #####################################/ static osg.Group rootNode # Create some geometry upon which to render GLSL shaders. static osg.Geode* CreateModel() geode = osg.Geode() geode.addDrawable(osg.ShapeDrawable(osg.Sphere(osg.Vec3(0.0,0.0,0.0),1.0))) geode.addDrawable(osg.ShapeDrawable(osg.Cone(osg.Vec3(2.2,0.0,-0.4),0.9,1.8))) geode.addDrawable(osg.ShapeDrawable(osg.Cylinder(osg.Vec3(4.4,0.0,0.0),1.0,1.4))) return geode # Add a reference to the masterModel at the specified translation, and # return its StateSet so we can easily attach StateAttributes. static osg.StateSet* ModelInstance() static float zvalue = 0.0 static osg.Node* masterModel = CreateModel() xform = osg.PositionAttitudeTransform() xform.setPosition(osg.Vec3( 0.0, -1.0, zvalue )) zvalue = zvalue + 2.2 xform.addChild(masterModel) rootNode.addChild(xform) return xform.getOrCreateStateSet()