private void defineBox(UWB_PrimitiveList list, Vector3 min, Vector3 max) { UWB_PrimitiveLine l = new UWB_PrimitiveLine(); l.setStartPoint(min.X, min.Y, min.Z); l.setEndPoint(max.X, min.Y, min.Z); list.append(l); l = new UWB_PrimitiveLine(); l.setStartPoint(min.X, min.Y, min.Z); l.setEndPoint(min.X, max.Y, min.Z); list.append(l); l = new UWB_PrimitiveLine(); l.setStartPoint(min.X, min.Y, min.Z); l.setEndPoint(min.X, min.Y, max.Z); list.append(l); l = new UWB_PrimitiveLine(); l.setStartPoint(max.X, max.Y, max.Z); l.setEndPoint(min.X, max.Y, max.Z); list.append(l); l = new UWB_PrimitiveLine(); l.setStartPoint(max.X, max.Y, max.Z); l.setEndPoint(max.X, min.Y, max.Z); list.append(l); l = new UWB_PrimitiveLine(); l.setStartPoint(max.X, max.Y, max.Z); l.setEndPoint(max.X, max.Y, min.Z); list.append(l); l = new UWB_PrimitiveLine(); l.setStartPoint(min.X, max.Y, min.Z); l.setEndPoint(max.X, max.Y, min.Z); list.append(l); l = new UWB_PrimitiveLine(); l.setStartPoint(min.X, max.Y, min.Z); l.setEndPoint(min.X, max.Y, max.Z); list.append(l); l = new UWB_PrimitiveLine(); l.setStartPoint(min.X, min.Y, max.Z); l.setEndPoint(max.X, min.Y, max.Z); list.append(l); l = new UWB_PrimitiveLine(); l.setStartPoint(min.X, min.Y, max.Z); l.setEndPoint(min.X, max.Y, max.Z); list.append(l); l = new UWB_PrimitiveLine(); l.setStartPoint(max.X, min.Y, min.Z); l.setEndPoint(max.X, max.Y, min.Z); list.append(l); }
internal void AddDebugRays(RayTracer_552.RTCore rtCore) { if (null == rtCore) return; while ((mShownRayY < rtCore.CurrentY) || (((mShownRayY == rtCore.CurrentY) && (mShownRayX < rtCore.CurrentX)))) { lock (rtCore) { Vector3 p = new Vector3(); System.Drawing.Color c = new System.Drawing.Color(); float dist; rtCore.GetPixelValues(mShownRayX, mShownRayY, out p, out c, out dist); if (rtCore.DisplayDebugRays()) { UWB_PrimitiveLine line = new UWB_PrimitiveLine(); Vector3 v = p - mCameraPosition; float len = v.Length(); v /= len; if (dist > (float.MaxValue / 2f)) dist = len; p = mCameraPosition + dist * v; line.setStartPoint(mCameraPosition.X, mCameraPosition.Y, mCameraPosition.Z); line.setEndPoint(p.X, p.Y, p.Z); line.Material.Diffuse = Vector4.Zero; line.Material.Specular = Vector4.Zero; line.Material.Ambient = Vector4.Zero; line.Material.Emissive = Vector4.One; mRaysToShow.append(line); } mShownRayX++; if (mShownRayX >= rtCore.ImageWidth) { mShownRayX = 0; mShownRayY++; } } } }
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); }
internal void AddImageFrame(RayTracer_552.RTCore rtCore) { if (null == rtCore) return; // construct the image frame Vector3 tl = rtCore.GetTopLeftPixelPosition(); Vector3 tr = rtCore.GetTopRightPixelPosition(); Vector3 bl = rtCore.GetBottomLeftPixelPosition(); Vector3 br = rtCore.GetBottomRightPixelPosition(); UWB_PrimitiveLine t, b, l, r; t = new UWB_PrimitiveLine(); b = new UWB_PrimitiveLine(); l = new UWB_PrimitiveLine(); r = new UWB_PrimitiveLine(); t.setStartPoint(tr.X, tr.Y, tr.Z); t.setEndPoint(tl.X, tl.Y, tl.Z); t.Material.Emissive = Vector4.UnitX; l.setStartPoint(tl.X, tl.Y, tl.Z); l.setEndPoint(bl.X, bl.Y, bl.Z); l.Material.Emissive = Vector4.UnitX; b.setStartPoint(br.X, br.Y, br.Z); b.setEndPoint(bl.X, bl.Y, bl.Z); b.Material.Emissive = Vector4.UnitX; r.setStartPoint(tr.X, tr.Y, tr.Z); r.setEndPoint(br.X, br.Y, br.Z); r.Material.Emissive = Vector4.UnitX; mCameraPrimitives.append(t); mCameraPrimitives.append(b); mCameraPrimitives.append(l); mCameraPrimitives.append(r); }