#!/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 osgUtil import math import OpenGL from OpenGL.GL import * class UpdateCameraAndTexGenCallback(osg.NodeCallback): def __init__(self, position, cameraNode, texgenNode): osg.NodeCallback.__init__(self) self._position = position self._cameraNode = cameraNode self._texgenNode = texgenNode def apply(self,node,nv): # first update subgraph to make sure objects are all moved into postion self.traverse(node,nv) # now compute the camera's view and projection matrix to point at the shadower (the camera's children) bs = osg.BoundingSphere() for i in range(self._cameraNode.getNumChildren()): bs.expandBy(self._cameraNode.getChild(i).getBound()) if (not bs): print osg.notify(osg.WARN) + "bb invalid" + self._cameraNode return centerDistance = (self._position-bs.center()).length() znear = centerDistance-bs.radius() zfar = centerDistance+bs.radius() zNearRatio = 0.001 if (znear