Trying to implement Panda3D Gizmo in Ogre

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
ja0335
Gremlin
Posts: 154
Joined: Sun Jun 07, 2009 9:04 pm
Location: Bogotá, Colombia
x 4
Contact:

Trying to implement Panda3D Gizmo in Ogre

Post by ja0335 »

hi..

I am currently trying to migrate a gizmo panda code to Ogre, but i fall in a black hole in below part because i don't know how to translate it to Ogre.

Panda source http://www.panda3d.org/forums/viewtopic.php?t=10768

Code: Select all


def GetAxisPoint( self, axis ):
        
        def __GetMousePlaneCollisionPoint( planeNormal ):
        
            """
            Return the collision point of a ray fired through the mouse and a
            plane with the specified normal.
            """
            
            # Fire a ray from the camera through the mouse 
            mp = base.mouseWatcherNode.getMouse()
            p1 = Point3()
            p2 = Point3()
            self.camera.node().getLens().extrude( mp, p1, p2 )
            p1 = render.getRelativePoint( self.camera, p1 )
            p2 = render.getRelativePoint( self.camera, p2 )
            
            # Get the point of intersection with a plane with the normal specified
            p = Point3()
            Plane( planeNormal, self.getPos() ).intersectsLine( p, p1, p2 )
            
            return p
        
        def __ClosestPointToLine( c, a, b ):
    
            """Returns the closest point on line ab to input point c."""

            u = ( c[0] - a[0] ) * ( b[0] - a[0] ) + ( c[1] - a[1] ) * ( b[1] - a[1] ) + ( c[2] - a[2] ) * ( b[2] - a[2] )
            u = u / ( ( a - b ).length() * ( a - b ).length() )

            x = a[0] + u * ( b[0] - a[0] )
            y = a[1] + u * ( b[1] - a[1] )
            z = a[2] + u * ( b[2] - a[2] )

            return Point3(x, y, z)
        
        # Get the axis vector - by default this is the selected axis'
        # vector unless we need to use the camera's look vector
        if axis.vector == gz.CAMERA_VECTOR:
            axisVector = render.getRelativeVector( self.camera, Vec3(0, -1, 0) )
        else:
            axisVector = render.getRelativeVector( self, axis.vector )
            
        # Get the transform plane's normal. If we're transforming in
        # planar mode use the axis vector as the plane normal, otherwise
        # get the normal of a plane along the selected axis
        if self.planar or axis.planar:
            return __GetMousePlaneCollisionPoint( axisVector )
        else:
            
            # Get the cross of the camera vector and the axis vector - a
            # vector of 0, 1, 0 in camera space is coming out of the lens
            camVector = render.getRelativeVector( self.camera, Vec3(0, 1, 0) )
            camAxisCross = camVector.cross( axisVector )
            
            # Cross this back with the axis to get a plane's normal
            planeNormal = camAxisCross.cross( axisVector )
            p = __GetMousePlaneCollisionPoint( planeNormal )
            return __ClosestPointToLine( p, self.initTransform.getPos(), self.initTransform.getPos() + axisVector )

I don't understand and don't have idea what does and how translate it to ogre the native pana function "getRelativeVector".

Another thing is i would like understand the logic implemented to get the plane normal graphically with draws :D

Thanks a lot.
Juan Camilo Acosta Arango
Post Reply