public void Set(H3DCamera Camera) { BaseCamera = Camera; Animation.SetCamera(Camera); RecalculateMatrices(); }
public void SetCamera(H3DCamera Camera) { BaseCamera = Camera; ResetState(); }
public H3DCamera ToH3DCamera() { H3DCamera Output = new H3DCamera() { Name = Name }; Output.TransformTranslation = TransformTranslation; Output.TransformRotation = TransformRotation; Output.TransformScale = TransformScale; Output.ViewType = (H3DCameraViewType)ViewType; switch (ProjectionType) { case GfxCameraProjectionType.Perspective: Output.ProjectionType = H3DCameraProjectionType.Perspective; break; case GfxCameraProjectionType.Frustum: case GfxCameraProjectionType.Orthogonal: Output.ProjectionType = H3DCameraProjectionType.Orthogonal; break; } Output.WScale = WScale; bool InheritUpRot = false; bool InheritTargetRot = false; bool InheritTargetTrans = false; if (View is GfxCameraViewAim ViewAim) { Output.View = new H3DCameraViewAim() { Target = ViewAim.Target, Twist = ViewAim.Twist }; InheritTargetRot = (ViewAim.Flags & GfxCameraViewAimFlags.IsInheritingTargetRotation) != 0; InheritTargetTrans = (ViewAim.Flags & GfxCameraViewAimFlags.IsInheritingTargetTranslation) != 0; } else if (View is GfxCameraViewLookAt ViewLookAt) { Output.View = new H3DCameraViewLookAt() { Target = ViewLookAt.Target, UpVector = ViewLookAt.UpVector }; InheritUpRot = (ViewLookAt.Flags & GfxCameraViewLookAtFlags.IsInheritingUpRotation) != 0; InheritTargetRot = (ViewLookAt.Flags & GfxCameraViewLookAtFlags.IsInheritingTargetRotation) != 0; InheritTargetTrans = (ViewLookAt.Flags & GfxCameraViewLookAtFlags.IsInheritingTargetTranslation) != 0; } else if (View is GfxCameraViewRotation ViewRotation) { Output.View = new H3DCameraViewRotation() { Rotation = ViewRotation.Rotation }; InheritTargetRot = ViewRotation.IsInheritingRotation; } if (Projection is GfxCameraProjectionPerspective ProjPersp) { Output.Projection = new H3DCameraProjectionPerspective() { ZNear = ProjPersp.ZNear, ZFar = ProjPersp.ZFar, AspectRatio = ProjPersp.AspectRatio, FOVY = ProjPersp.FOVY }; } else if ( Projection is GfxCameraProjectionFrustum || Projection is GfxCameraProjectionOrthogonal) { GfxCameraProjectionOrthogonal ProjOrtho = (GfxCameraProjectionOrthogonal)Projection; Output.Projection = new H3DCameraProjectionOrthogonal() { ZNear = ProjOrtho.ZNear, ZFar = ProjOrtho.ZFar, AspectRatio = ProjOrtho.AspectRatio, Height = ProjOrtho.Height }; } if (InheritUpRot) { Output.Flags |= H3DCameraFlags.IsInheritingUpRotation; } if (InheritTargetRot) { Output.Flags |= H3DCameraFlags.IsInheritingTargetRotation; } if (InheritTargetTrans) { Output.Flags |= H3DCameraFlags.IsInheritingTargetTranslation; } return(Output); }
public GfxCamera(H3DCamera Cam) { Header = new GfxRevHeader("CCAM"); Name = Cam.Name; TransformTranslation = Cam.TransformTranslation; TransformRotation = Cam.TransformRotation; TransformScale = Cam.TransformScale; ViewType = (GfxCameraViewType)Cam.ViewType; GfxAnimGroup Group = new GfxAnimGroup(); Group.Name = "CameraAnimation"; Group.MemberType = 5; GfxAnimGroupTransform TransformGrp = new GfxAnimGroupTransform(); Group.Elements.Add(TransformGrp); GfxAnimGroupViewUpdater VUTwist = new GfxAnimGroupViewUpdater("Twist", 1, 1, 8); GfxAnimGroupViewUpdater VUTargetPos = new GfxAnimGroupViewUpdater("TargetPosition", 0, 1, 8); GfxAnimGroupViewUpdater VUUpVec = new GfxAnimGroupViewUpdater("UpwardVector", 2, 1, 20); GfxAnimGroupViewUpdater VURotate = new GfxAnimGroupViewUpdater("ViewRotate", 3, 1, 8); switch (Cam.ViewType) { case H3DCameraViewType.LookAt: Group.Elements.Add(VUTargetPos); Group.Elements.Add(VUUpVec); break; case H3DCameraViewType.Aim: Group.Elements.Add(VUTargetPos); Group.Elements.Add(VUTwist); break; case H3DCameraViewType.Rotate: Group.Elements.Add(VURotate); break; } GfxAnimGroupProjectionUpdater PUZNear = new GfxAnimGroupProjectionUpdater("Near", 0, 2, 4); GfxAnimGroupProjectionUpdater PUZFar = new GfxAnimGroupProjectionUpdater("Far", 1, 2, 8); GfxAnimGroupProjectionUpdater PUZFovY = new GfxAnimGroupProjectionUpdater("Fovy", 2, 2, 16); GfxAnimGroupProjectionUpdater PUZAspect = new GfxAnimGroupProjectionUpdater("AspectRatio", 3, 2, 12); Group.BlendOperationTypes = new int[] { 4, 6, 2 }; Group.Elements.Add(PUZNear); Group.Elements.Add(PUZFar); IsBranchVisible = true; switch (Cam.ProjectionType) { case H3DCameraProjectionType.Perspective: Group.Elements.Add(PUZFovY); Group.Elements.Add(PUZAspect); break; } AnimationsGroup.Add(Group); switch (Cam.ProjectionType) { case H3DCameraProjectionType.Orthogonal: ProjectionType = GfxCameraProjectionType.Orthogonal; break; case H3DCameraProjectionType.Perspective: ProjectionType = GfxCameraProjectionType.Perspective; break; } WScale = Cam.WScale; if (Cam.View is H3DCameraViewAim ViewAim) { View = new GfxCameraViewAim() { Target = ViewAim.Target, Twist = ViewAim.Twist, Flags = (GfxCameraViewAimFlags)((int)Cam.Flags & 0b11) }; } else if (Cam.View is H3DCameraViewLookAt LookAt) { View = new GfxCameraViewLookAt() { Target = LookAt.Target, UpVector = LookAt.UpVector, Flags = (Cam.Flags.HasFlag(H3DCameraFlags.IsInheritingUpRotation) ? GfxCameraViewLookAtFlags.IsInheritingUpRotation : 0) | (Cam.Flags.HasFlag(H3DCameraFlags.IsInheritingTargetTranslation) ? GfxCameraViewLookAtFlags.IsInheritingTargetTranslation : 0) | (Cam.Flags.HasFlag(H3DCameraFlags.IsInheritingTargetRotation) ? GfxCameraViewLookAtFlags.IsInheritingTargetRotation : 0) }; } else if (Cam.View is H3DCameraViewRotation ViewRotation) { View = new GfxCameraViewRotation() { Rotation = ViewRotation.Rotation, IsInheritingRotation = Cam.Flags.HasFlag(H3DCameraFlags.IsInheritingTargetRotation) }; } if (Cam.Projection is H3DCameraProjectionPerspective Persp) { Projection = new GfxCameraProjectionPerspective() { AspectRatio = Persp.AspectRatio, FOVY = Persp.FOVY, ZFar = Persp.ZFar, ZNear = Persp.ZNear }; } else if (Cam.Projection is H3DCameraProjectionOrthogonal Ortho) { Projection = new GfxCameraProjectionOrthogonal() { AspectRatio = Ortho.AspectRatio, Height = Ortho.Height, ZFar = Ortho.ZFar, ZNear = Ortho.ZNear }; } }