/// <summary> /// input ray is in Object (local) coords of so, apply all intermediate /// transforms to get it to Scene coords /// </summary> public static Ray3f ObjectToScene(SceneObject so, Ray3f objectRay) { Ray3f sceneRay = objectRay; SceneObject curSO = so; while (curSO != null) { Frame3f curF = curSO.GetLocalFrame(CoordSpace.ObjectCoords); Vector3f scale = curSO.GetLocalScale(); Vector3f new_o = curF.FromFrameP(sceneRay.Origin * scale); Vector3f new_d = curF.FromFrameV(sceneRay.Direction * scale); sceneRay = new Ray3f(new_o, new_d.Normalized); SOParent parent = curSO.Parent; if (parent is FScene) { return(sceneRay); } curSO = (parent as SceneObject); } if (curSO == null) { DebugUtil.Error("SceneTransforms.ObjectToScene: found null parent SO!"); } return(sceneRay); }
/// <summary> /// input objectF is in Object (local) coords of so, apply all intermediate /// transforms to get it to Scene coords /// </summary> public static Frame3f ObjectToScene(SceneObject so, Frame3f objectF) { Frame3f sceneF = objectF; SceneObject curSO = so; while (curSO != null) { Frame3f curF = curSO.GetLocalFrame(CoordSpace.ObjectCoords); Vector3f scale = curSO.GetLocalScale(); Util.gDevAssert(curSO == so || IsUniformScale(scale)); sceneF.Scale(scale); sceneF = curF.FromFrame(ref sceneF); SOParent parent = curSO.Parent; if (parent is FScene) { return(sceneF); } curSO = (parent as SceneObject); } if (curSO == null) { DebugUtil.Error("SceneTransforms.ObjectToScene: found null parent SO!"); } return(sceneF); }
/// <summary> /// Input sceneF is a frame in Scene, apply all intermediate inverse /// transforms to get it into local frame of a SO /// </summary> public static Frame3f SceneToObject(TransformableSO so, Frame3f sceneF) { SOParent parent = so.Parent; if (parent is FScene) { return(ApplyInverseTransform(so, sceneF)); } // this will recursively apply all the inverse parent transforms from scene on down return(ApplyInverseTransform(so, SceneToObject(parent as TransformableSO, sceneF))); }
/// <summary> /// Input ray is a frame in Scene, apply all intermediate inverse /// transforms to get it into local frame of a SO /// </summary> public static Ray3f SceneToObject(SceneObject so, Ray3f ray) { SOParent parent = so.Parent; if (parent is FScene) { return(ApplyInverseTransform(so, ray)); } // this will recursively apply all the inverse parent transforms from scene on down return(ApplyInverseTransform(so, SceneToObject(parent as SceneObject, ray))); }
/// <summary> /// Cache the transform sequence from SO up to scene coordinates /// </summary> public static TransformSequence ObjectToSceneXForm(SceneObject so) { TransformSequence seq = new TransformSequence(); SceneObject curSO = so; while (curSO != null) { Frame3f curF = curSO.GetLocalFrame(CoordSpace.ObjectCoords); Vector3f scale = curSO.GetLocalScale(); seq.AppendScale(scale); seq.AppendFromFrame(curF); SOParent parent = curSO.Parent; if (parent is FScene) { break; } curSO = (parent as SceneObject); } return(seq); }
/// <summary> /// input objectF is in Object (local) coords of so, apply all intermediate /// transforms to get it to Scene coords /// </summary> public static Vector3f ObjectToSceneP(SceneObject so, Vector3f objectPt) { SceneObject curSO = so; while (curSO != null) { Frame3f curF = curSO.GetLocalFrame(CoordSpace.ObjectCoords); Vector3f scale = curSO.GetLocalScale(); objectPt = curF.FromFrameP(objectPt * scale); SOParent parent = curSO.Parent; if (parent is FScene) { return(objectPt); } curSO = (parent as SceneObject); } if (curSO == null) { DebugUtil.Error("SceneTransforms.ObjectToSceneP: found null parent SO!"); } return(objectPt); }
/// <summary> /// input dimension is in Object (local) coords of so, apply all intermediate /// transform scaling to get it to Scene coords /// </summary> public static float ObjectToScene(SceneObject so, float objectDim) { float sceneDim = objectDim; SceneObject curSO = so; while (curSO != null) { Vector3f scale = curSO.GetLocalScale(); Util.gDevAssert(IsUniformScale(scale)); sceneDim *= ((scale.x + scale.y + scale.z) / 3.0f); // yikes! SOParent parent = curSO.Parent; if (parent is FScene) { return(sceneDim); } curSO = (parent as SceneObject); } if (curSO == null) { DebugUtil.Error("SceneTransforms.ObjectToScene: found null parent SO!"); } return(sceneDim); }
/// <summary> /// input objectF is in Object (local) coords of so, apply all intermediate /// transforms to get it to Scene coords /// </summary> public static Frame3f ObjectToScene(TransformableSO so, Frame3f objectF) { Frame3f sceneF = objectF; TransformableSO curSO = so; while (curSO != null) { Frame3f curF = curSO.GetLocalFrame(CoordSpace.ObjectCoords); Vector3f scale = curSO.GetLocalScale(); sceneF.Scale(scale); sceneF = curF.FromFrame(sceneF); SOParent parent = curSO.Parent; if (parent is FScene) { return(sceneF); } curSO = (parent as TransformableSO); } if (curSO == null) { DebugUtil.Error("SceneTransforms.TransformTo: found null parent SO!"); } return(sceneF); }
/// <summary> /// Input objectV is a vector in local coords of SO, apply all intermediate inverse /// transforms to get it into scene coords. /// </summary> public static Vector3f ObjectToSceneV(SceneObject so, Vector3f objectV) { Vector3f sceneV = objectV; SceneObject curSO = so; while (curSO != null) { Frame3f curF = curSO.GetLocalFrame(CoordSpace.ObjectCoords); Vector3f scale = curSO.GetLocalScale(); sceneV *= scale; sceneV = curF.FromFrameV(ref sceneV); SOParent parent = curSO.Parent; if (parent is FScene) { return(sceneV); } curSO = (parent as SceneObject); } if (curSO == null) { DebugUtil.Error("SceneTransforms.ObjectToSceneV: found null parent SO!"); } return(sceneV); }