public BuildingFreeCamera(CameraProps props, IInputService inputService, ICollisionMesh collisionMesh, IStoryLayoutZoning zoning) { this.props = Props.FromCommonProps(props.Frame); this.inputService = inputService; this.collisionMesh = collisionMesh; this.zoning = zoning; }
public int GetClosestNodeId(CameraProps cameraProps) { return(storyGraph.Leaves .Select(x => storyGraph.NodeObjects[x]) .Minimal(x => (x.GlobalTransform.Offset - cameraProps.Frame.Eye).LengthSquared()) .Id); }
public CameraContext(Camera camera, CameraProps props) { cam = camera; cachedCamProps = CameraProps.FromCamera(cam); props.Apply(cam); }
public void Update(FrameTime frameTime) { var camera = globalObjectService.MainCamera; var frame = new CameraFrame(camera.transform.position.ToClarity(), camera.transform.rotation.ToClarity()); var proj = new CameraProjection(CameraProjectionType.Perspective, camera.nearClipPlane, camera.farClipPlane, camera.fieldOfView); props = new CameraProps(frame.Eye + frame.Forward, frame, proj); }
public StoryPathCamera(IStoryPath storyPath, CameraProps initialCameraProps, CameraProps?finalCameraProps, Action onComplete) { this.storyPath = storyPath; this.initialCameraProps = initialCameraProps; this.finalCameraProps = finalCameraProps; this.onComplete = onComplete; time = 0f; }
public IStoryPath GetPath(CameraProps initialCameraProps, int endNodeId, NavigationState navigationState, bool interLevel) { var endNode = storyGraph.NodeObjects[storyGraph.Root].Scene.World.GetNodeById(endNodeId); var aEndFocus = endNode.GetComponent <IFocusNodeComponent>(); var endCameraInfo = aEndFocus.DefaultViewpointMechanism.FixedCamera.GetProps(); return(new DirectStoryPath(initialCameraProps, endCameraInfo, PathDefaultDuration)); }
public void TeleportTo(CameraProps newProps, float?floorHeight) { var player = globalObjectService.VrPlayerCarrier; var eye = newProps.Frame.Eye; if (floorHeight.HasValue) { eye.Y = floorHeight.Value; } player.transform.position = eye.ToUnity(); player.transform.rotation = newProps.Frame.GetRotation().ToUnity(); }
public void NavigateTo(ISceneNode node, IStoryPath storyPath, CameraProps initialCameraProps, float?initialFloorHeight, float?targetFloorHeight) { var cFocusNode = node.GetComponent <IFocusNodeComponent>(); var newCamera = cFocusNode.DefaultViewpointMechanism.CreateControlledViewpoint(); if (initialFloorHeight.HasValue) { initialCameraProps.Frame.Eye.Y = initialFloorHeight.Value + 2; } currentPathCamera = new StoryPathCamera(storyPath, initialCameraProps, newCamera.GetProps(), () => hasFinished = true); floorHeightOffset = initialFloorHeight.HasValue ? 2//initialCameraProps.Frame.Eye.Y - floorHeight.Value : 0; hasFinished = false; }
public void Update(FrameTime frameTime) { if (isComplete) { return; } time += frameTime.DeltaSeconds; if (!storyPath.HasFinished) { storyPath.Update(frameTime); completeTime = Math.Max(1f, time + storyPath.MaxRemainingTime); } visualProps = storyPath.GetCurrentCameraProps(); var acceleratingTime = MathHelper.Clamp(completeTime, 0f, 1f); if (time < acceleratingTime) { visualProps = CameraProps.Lerp(initialCameraProps, visualProps, time / acceleratingTime); } var actualFinalCameraProps = finalCameraProps ?? storyPath.GetCurrentCameraProps(); var brakingTime = MathHelper.Clamp(completeTime - acceleratingTime, 0f, 1f); var remainingTime = brakingTime + completeTime - time; if (remainingTime < brakingTime) { visualProps = CameraProps.Lerp(visualProps, actualFinalCameraProps, (brakingTime - remainingTime) / brakingTime); } if (remainingTime < 0) { visualProps = actualFinalCameraProps; onComplete(); isComplete = true; } }
public void NavigateTo(ISceneNode node, IStoryPath storyPath, CameraProps initialCameraProps, float?initialFloorHeight, float?targetFloorHeight) { TeleportTo(globalObjectService.VrPlayerCarrier, node, targetFloorHeight); }
public IControlledCamera CreateWarpCamera(CameraProps initialCameraProps) => throw new NotSupportedException();
private CameraProps GetCameraAt(float timestamp) { var amount = GetLerpAmount(timestamp); return(CameraProps.Lerp(StartCameraProps, EndCameraProps, amount)); }
public void Update(FrameTime frameTime) { if (HasFinished) { return; } if (path.Length == 0) { HasFinished = true; return; } curentTimestamp += frameTime.DeltaSeconds; var speed = GetSpeed(currentSegment, currentDist); var dist = currentDist + frameTime.DeltaSeconds * speed; while (dist > 0) { if (dist > path[currentSegment].Length) { if (currentSegment == path.Length - 1) { HasFinished = true; currentDist = path[currentSegment].Length; dist = 0; } else { dist -= path[currentSegment].Length; currentSegment++; } } else { currentDist = dist; dist = 0; } } var segment = path[currentSegment]; var eye = segment.StartPoint + segment.Direction * currentDist + Vector3.UnitY * BuildingConstants.LeafHalfSize.Height; Vector3 forward; if (segment.Direction.Xz.LengthSquared() > MathHelper.Eps8) { forward = segment.Direction.Y == 0 ? segment.Direction : new Vector3(segment.Direction.X, 0, segment.Direction.Z).Normalize(); } else { var amount = currentDist / segment.Length; forward = segment.StartPoint.X > 0 ? Vector3.UnitX * Quaternion.RotationY(MathHelper.Pi * amount) : -Vector3.UnitX * Quaternion.RotationY(MathHelper.Pi * amount); } //var forward = new Vector3(segment.Direction.X, 0, segment.Direction.Z).Normalize(); var target = eye + forward * speed / 2; // todo: to constants //var up = Math.Abs(Vector3.Cross(forward, Vector3.UnitY).LengthSquared()) < MathHelper.Eps8 // ? eye.X < 0 // ? -Vector3.UnitX // : Vector3.UnitX // : Vector3.UnitY; var up = Vector3.UnitY; currentCameraProps = new CameraProps(target, new CameraFrame(eye, forward, up), new CameraProjection(CameraProjectionType.Perspective, 0.1f, 100f, MathHelper.PiOver4)); }
public BuildingStoryPath(BuildingStoryLayoutPlacementAlgorithm pa, IStoryGraph sg, CameraProps initialCameraProps, int endNodeId, NavigationState navigationState, bool interLevel) { this.pa = pa; this.sg = sg; beziers = new List <BezierQuadratic3>(); var closestNode = sg.Leaves.Minimal(x => (BuildingConstants.LeafHalfSize.Depth * Vector3.UnitZ * GetGlobalTransform(x) - initialCameraProps.Frame.Eye).LengthSquared()); //var closestNodeGlobalTransform = GetGlobalTransform(endNodeId); //var closestNodeCenter = Vector3.Zero * closestNodeGlobalTransform; //var closestNodeConnector = BuildingConstants.LeafHalfSize.Depth * Vector3.UnitZ * closestNodeGlobalTransform; if (closestNode != endNodeId || interLevel) { if (!interLevel && sg.TryFindShortestPath(closestNode, endNodeId, out var nodePath)) { foreach (var edge in nodePath.SequentialPairs()) { IEnumerable <BezierQuadratic3> pathToAdd; if (pa.Lanes.TryGetValue(edge, out var lane)) { pathToAdd = lane.GlobalPath; } else if (pa.Lanes.TryGetValue(edge.Reverse(), out lane)) { pathToAdd = lane.GlobalPath.Reverse().Select(x => x.Reverse()); } else { throw new Exception("Path search returned an unexisting path."); } beziers.AddRange(pathToAdd.Skip(1).ExceptLast()); } } else { var endNode = sg.NodeObjects[endNodeId]; var aEndFocus = endNode.GetComponent <IFocusNodeComponent>(); var endCameraInfo = aEndFocus.DefaultViewpointMechanism.FixedCamera.GetProps(); directPath = new DirectStoryPath(initialCameraProps, endCameraInfo, 1f); } } switch (navigationState) { case NavigationState.AtNode: break; case NavigationState.AtForwardFork: { var nextEdge = new Pair <int>(endNodeId, sg.Next[endNodeId].First()); var nextLane = pa.Lanes[nextEdge]; var lastBezier = nextLane.GlobalPath.First(); var point = lastBezier.At(1); var tangent = lastBezier.TangentAt(1); beziers.Add(BezierQuadratic3.Straight(point - tangent, point)); break; } case NavigationState.AtBackwardFork: { var nextEdge = new Pair <int>(sg.Previous[endNodeId].First(), endNodeId); var nextLane = pa.Lanes[nextEdge]; var lastBezier = nextLane.GlobalPath.Last().Reverse(); var point = lastBezier.At(1); var tangent = lastBezier.TangentAt(1); beziers.Add(BezierQuadratic3.Straight(point - tangent, point)); break; } default: throw new ArgumentOutOfRangeException(nameof(navigationState), navigationState, null); } foreach (var indexPair in Enumerable.Range(0, beziers.Count).SequentialPairs()) { if (beziers[indexPair.First].P2 != beziers[indexPair.Second].P0) { var avg = (beziers[indexPair.First].P2 + beziers[indexPair.Second].P0) / 2; beziers[indexPair.First] = beziers[indexPair.First].With((ref BezierQuadratic3 b) => b.P2 = avg); beziers[indexPair.Second] = beziers[indexPair.Second].With((ref BezierQuadratic3 b) => b.P0 = avg); } } if (!beziers.Any()) { beziers.Add(BezierQuadratic3.Straight(initialCameraProps.Frame.Eye, initialCameraProps.Frame.Eye + initialCameraProps.Frame.Forward)); } path = beziers .SelectMany(x => x.ToEnumPolyline(BezierTolerance)) .SequentialPairs() .Select(x => new PathSegment(x.First, x.Second)) .Where(x => x.Length > 0) .ToArray(); currentCameraProps = initialCameraProps; }
public DirectStoryPath(CameraProps startCameraProps, CameraProps endCameraProps, float defaultDuration) { StartCameraProps = startCameraProps; EndCameraProps = endCameraProps; DefaultDuration = defaultDuration; }
public IStoryPath GetPath(CameraProps initialCameraProps, int endNodeId, NavigationState navigationState, bool interLevel) { return(new BuildingStoryPath(placementAlgorithm, sg, initialCameraProps, endNodeId, navigationState, interLevel)); }
static extern IntPtr fu_camera_handler_get_camera_props( int device_index, out CameraProps props);
public int GetClosestNodeId(CameraProps cameraProps) { return(sg.Leaves.Minimal(x => (placementAlgorithm.GetGlobalTransform(x).Offset - cameraProps.Target).LengthSquared())); }
public IControlledCamera CreateWarpCamera(CameraProps initialCameraProps) { return(new BuildingFreeCamera(initialCameraProps, inputService, collisionMesh, zoning)); //return new BuildingWarpCamera(initialCameraProps, collisionMesh, placementAlgorithm, inputService); }
public IControlledCamera CreateFreeCamera(CameraProps initialCameraProps) { return(new BuildingFreeCamera(initialCameraProps, inputService, collisionMesh, zoning)); }