コード例 #1
0
 public bool GetNodeBounds(ref UWB_SceneNode pSearchNode,
                           ref UWB_BoundingBox box,
                           ref UWB_DrawHelper helper,
                           bool bDraw)
 {
     return(GetNodeBoundsHelper(ref pSearchNode, ref box, ref helper, 0, bDraw));
 }
コード例 #2
0
 internal void AddRTKdTree(RayTracer_552.KdTreeNode rootNode)
 {
     UWB_SceneNode n = new UWB_SceneNode();
     m_SceneDatabase.insertChildNode(n);
     UWB_PrimitiveList list = new UWB_PrimitiveList();
     n.setPrimitive(list);
     AddBox(rootNode, list);
 }
コード例 #3
0
        protected bool GetNodeBoundsHelper(ref UWB_SceneNode pSearchNode,
                                           ref UWB_BoundingBox box,
                                           ref UWB_DrawHelper helper, int level, bool bDraw)
        {
            bool found = false;

            if (Object.ReferenceEquals(this, pSearchNode))
            {
                box   = this.GetBounds(ref helper, bDraw);
                found = true;
            }
            else
            {
                helper.pushModelTransform();
                {
                    level++;
                    this.getXFormInfo().setupModelStack(helper);

                    int count = this.numChildren();
                    for (int i = 0; i < count; i++)
                    {
                        UWB_SceneNode pChildNode = this.getChildNode(i);
                        if (pChildNode.GetNodeBoundsHelper(ref pSearchNode, ref box, ref helper, level, bDraw))
                        {
                            found = true;
                            break;
                        }
                    }
                    level--;
                }
                helper.popModelTransform();
            }
            if (0 == level && found && bDraw)
            {
                helper.resetAttributes();
                helper.setColor1(new Color(0, 0, 255));
                helper.setShadeMode(eShadeMode.smFlat);
                helper.setFillMode(eFillMode.fmWireframe);
                box.Draw(ref helper);
            }

            return(found);
        }
コード例 #4
0
        internal RTModelViewer()
        {
            m_DrawHelper.initializeModelTransform();

            m_RootNode = new UWB_SceneNode("Scene");
            NewSceneDatabase();
            mCamera = new UWB_SceneNode();

            UWB_SceneNode pAxisNode = new UWB_SceneNode("axis frame");
            UWB_XFormInfo xf = pAxisNode.getXFormInfo();
            xf.SetScale(new Vector3(3.0f, 3.0f, 3.0f));
            pAxisNode.setXFormInfo(xf);
            UWB_XNAPrimitiveMeshAxis pMeshAxis = new UWB_XNAPrimitiveMeshAxis();
            //pMeshAxis.EnableBlending(true);
            pAxisNode.setPrimitive(pMeshAxis);
            m_RootNode.insertChildNode(pAxisNode);

            m_WorldBounds.setCorners( new Vector3(-100,-100,-100), new Vector3(100,100,100) );
        }
コード例 #5
0
 public void insertChildNode(UWB_SceneNode childNode)
 {
     mChildNodes.append(childNode);
 }
コード例 #6
0
 private void NewSceneDatabase()
 {
     m_SceneDatabase = new UWB_SceneNode();
     mCamera = new UWB_SceneNode();
     mCameraPrimitives = new UWB_PrimitiveList();
 }
コード例 #7
0
 private UWB_SceneNode CreateNode(Vector3 at, float sx, float sy, float sz, UWB_Primitive prim)
 {
     UWB_SceneNode pNode = new UWB_SceneNode();
     pNode.setPrimitive(prim);
     UWB_XFormInfo xf = pNode.getXFormInfo();
     xf.SetTranslation(at);
     xf.SetScale(new Vector3(sx, sy, sz));
     pNode.setXFormInfo(xf);
     m_SceneDatabase.insertChildNode(pNode);
     return pNode;
 }
コード例 #8
0
        private void AddCamera(RayTracer_552.RTCamera c)
        {
            // Look at position
            UWB_SceneNode atN = new UWB_SceneNode();
            UWB_XNAPrimitiveMesh at = new UWB_XNAPrimitiveMesh("sphere");
            at.Material.Diffuse = new Vector4(0.8f, 0.1f, 0.1f, 1.0f);
            atN.setPrimitive(at);
            UWB_XFormInfo atxf = atN.getXFormInfo();
            atxf.SetTranslation(c.AtPosition);
            atxf.SetScale(new Vector3(0.3f, 0.3f, 0.3f));
            atN.setXFormInfo(atxf);

            // Eye position
            UWB_SceneNode eyeN = new UWB_SceneNode();
            UWB_XNAPrimitiveMesh eye = new UWB_XNAPrimitiveMesh("cone");
            eyeN.setPrimitive(eye);
            UWB_XFormInfo eyexf = eyeN.getXFormInfo();
            eyexf.SetTranslation(c.EyePosition);
            mCameraPosition = c.EyePosition;
            Vector3 init = new Vector3(0, 0, 1); // initial cone orientation
            Vector3 final = c.AtPosition - c.EyePosition;
            final = Vector3.Normalize(final);
            float dot = Vector3.Dot(init, final);
            if (Math.Abs(dot) < 0.9999)
            {
                float angle = (float)Math.Acos(dot);
                Vector3 axis = Vector3.Cross(init, final);
                axis = Vector3.Normalize(axis);
                Quaternion q = Quaternion.CreateFromAxisAngle(axis, angle);
                eyexf.SetRotationQuat(q);
            }
            eyeN.setXFormInfo(eyexf);

            // Lines ...
            UWB_SceneNode lineN = new UWB_SceneNode();
            mCameraPrimitives = new UWB_PrimitiveList();
            lineN.setPrimitive(mCameraPrimitives);
            UWB_PrimitiveLine l = new UWB_PrimitiveLine();
            l.setStartPoint(c.EyePosition.X, c.EyePosition.Y, c.EyePosition.Z);
            l.setEndPoint(c.AtPosition.X, c.AtPosition.Y, c.AtPosition.Z);
            mCameraPrimitives.append(l);

            mCamera.insertChildNode(lineN);
            mCamera.insertChildNode(atN);
            mCamera.insertChildNode(eyeN);
        }
コード例 #9
0
        internal void AddRTScene(RayTracer_552.RTCamera c, RayTracer_552.SceneDatabase rtScene)
        {
            UWB_Primitive prim;

            NewSceneDatabase();
            SceneResource<RTGeometry> allGeom = rtScene.GetAllGeom();
            for (int i = 0; i < allGeom.Count; i++)
            {
                RTGeometry g = (RTGeometry)allGeom.ResourceLookup(i);
                switch (g.GeomType()) {
                    case RTGeometry.RTGeometryType.Sphere:
                        RTSphere s = (RTSphere)g;
                        prim = CreateSphereMesh();
                        SetMeshMaterial(prim, rtScene.GetMaterial(s.GetMaterialIndex()));
                        float scale =s.Radius/2f;
                        CreateNode(s.Center, scale, scale, scale, prim);
                        break;
                    case RTGeometry.RTGeometryType.Rectangle:
                        RTRectangle r = (RTRectangle) g;
                        prim = CreateRectangle(r);
                        SetMeshMaterial(prim, rtScene.GetMaterial(r.GetMaterialIndex()));
                        UWB_SceneNode node = CreateNode(r.GetCenter(), r.GetUSize()/2f, 1f, r.GetVSize()/2f, prim);
                        // now rotate the y-vector of node to point towards r.Normal;
                        float dot = (float)Math.Abs(Vector3.Dot(Vector3.UnitY, r.GetNormal()));
                        if (dot < 0.9999f)
                        {
                            float angle = (float)Math.Acos(dot);
                            Vector3 axis = Vector3.Cross(Vector3.UnitY, r.GetNormal());
                            axis.Normalize();
                            Quaternion q = Quaternion.CreateFromAxisAngle(axis, angle);
                            UWB_XFormInfo xf = node.getXFormInfo();
                            xf.SetRotationQuat(q);
                            node.setXFormInfo(xf);
                        }
                        break;
                    case RTGeometry.RTGeometryType.Triangle:
                        RTTriangle t = (RTTriangle)g;
                        Vector3[] v = t.GetVertices();
                        prim = new UWB_PrimitiveTriangle(v[0], v[1], v[2]);
                        prim.EnableLighting(true);
                        prim.EnableTexturing(false);
                        SetMeshMaterial(prim, rtScene.GetMaterial(t.GetMaterialIndex()));
                        CreateNode(Vector3.Zero, 1f, 1f, 1f, prim);
                        break;
                    }
            }
            AddCamera(c);
            AddLights(rtScene);

            // to show ray list
            mShownRayX = mShownRayY = 0;
            mRaysToShow = new UWB_PrimitiveList();

            mDebugInfo = new UWB_SceneNode();
            mDebugInfo.setPrimitive(mRaysToShow);
            mDebugInfo.insertChildNode(mPixelsToShow.GetAllPixels());
            mDebugInfo.insertChildNode(mPixelInWorld.GetAllPixels());
        }
コード例 #10
0
        protected bool GetNodeBoundsHelper(ref UWB_SceneNode pSearchNode,
                                         ref UWB_BoundingBox box,
                                         ref UWB_DrawHelper helper, int level, bool bDraw)
        {
            bool found = false;
              if( Object.ReferenceEquals(this, pSearchNode))
              {
            box = this.GetBounds( ref helper, bDraw );
            found = true;
              }
              else
              {
            helper.pushModelTransform();
            {
              level++;
              this.getXFormInfo().setupModelStack(helper);

              int count = this.numChildren();
              for(int i=0; i<count; i++)
              {
                UWB_SceneNode pChildNode = this.getChildNode( i );
                if( pChildNode.GetNodeBoundsHelper(  ref pSearchNode, ref box, ref helper, level, bDraw ) )
                {
                  found = true;
                  break;
                }
              }
              level--;
            }
            helper.popModelTransform();
              }
              if (0 == level && found && bDraw)
              {
              helper.resetAttributes();
              helper.setColor1(new Color(0,0,255));
              helper.setShadeMode(eShadeMode.smFlat);
              helper.setFillMode(eFillMode.fmWireframe);
              box.Draw(ref helper);
              }

              return found;
        }
コード例 #11
0
 public void insertChildNode(UWB_SceneNode childNode)
 {
     mChildNodes.append(childNode);
 }
コード例 #12
0
 public bool GetNodeBounds( ref UWB_SceneNode pSearchNode,
                                    ref UWB_BoundingBox box,
                                    ref UWB_DrawHelper helper,
                                    bool bDraw)
 {
     return GetNodeBoundsHelper(ref pSearchNode, ref box, ref helper, 0, bDraw );
 }