public static Quaternion ComplementRotateQuaternion(CameraFrameData frame1, CameraFrameData frame2, float progress) { Quaternion q1 = Quaternion.RotationYawPitchRoll(frame1.CameraRotation.Y, frame1.CameraRotation.X, frame1.CameraRotation.Z); Quaternion q2 = Quaternion.RotationYawPitchRoll(frame2.CameraRotation.Y, frame2.CameraRotation.X, frame2.CameraRotation.Z); return(Quaternion.Slerp(q1, q2, progress)); }
private void CameraFrameDataUI(int frameIndex) { FrameData frameData = GetFrameData(frameIndex); CameraFrameData cameraFrameData = frameData.cameraFrameData; CameraData cameraData = cameraFrameData.cameraData; SpaceWithLabel(LabelEffectID); cameraData.id = TextField(cameraData.id); SpaceWithLabel(LabelCameraTriggerType); cameraData.triggerType = (CameraTriggerType)EnumPopup(cameraData.triggerType); SpaceWithLabel(LabelCameraFocusType); cameraData.focusType = (CameraFocusType)EnumPopup(cameraData.focusType); cameraFrameData.cameraData = cameraData; Controller.SetCameraFrameData(frameIndex, cameraFrameData); bool isDelete = SpaceWithButton(BtnDelete); if (isDelete) { Controller.DeleteCameraFrameData(frameIndex); } }
private void LeapFrame(CameraFrameData cf1, CameraFrameData cf2, CameraProvider cp, IProjectionMatrixProvider proj, float f) { float ProgX, ProgY, ProgZ, ProgR, ProgL, ProgP;; ProgX = cf1.Curves[0].Evaluate(f); ProgY = cf1.Curves[1].Evaluate(f); ProgZ = cf1.Curves[2].Evaluate(f); ProgR = cf1.Curves[3].Evaluate(f); ProgL = cf1.Curves[4].Evaluate(f); ProgP = cf1.Curves[5].Evaluate(f); cp.CameraLookAt = CGHelper.ComplementTranslate(cf1, cf2, new Vector3(ProgX, ProgY, ProgZ)); Quaternion rotation = CGHelper.ComplementRotateQuaternion(cf1, cf2, ProgR); float length = CGHelper.Lerp(cf1.Distance, cf2.Distance, ProgL); float angle = CGHelper.Lerp(cf1.ViewAngle, cf2.ViewAngle, ProgP); Vector3 Position2target = Vector3.TransformCoordinate(new Vector3(0, 0, 1), Matrix.RotationQuaternion(rotation)); Vector3 TargetPosition = cp.CameraLookAt + length * Position2target; cp.CameraPosition = TargetPosition; proj.Fovy = CGHelper.ToRadians(angle); }
void UpdateAddAndDisplayTiles(int cameraFrame, HashSet <int> framesNeededForDisplay) { // Add and Display tiles that we need for (int i = cameraFrame - tileBuffer; i < cameraFrame + tileBuffer; i++) { int ii = i; if (i < 0 && i % levelSize == 0) { ii = 0; } else if (i < 0) { ii = levelSize + (i % levelSize); } else if (i >= levelSize) { ii = i % levelSize; } int neededFrameNumber = ii; framesNeededForDisplay.Add(neededFrameNumber); // Do we already have this tile active? bool haveTile = false; foreach (int key in activeTiles.Keys) { if (key == neededFrameNumber) { haveTile = true; break; } } // We don't have it so create it and add it to activeTiles if (!haveTile) { int neededTileNumber = levelLayout[neededFrameNumber]; GameObject thistile = tileLookup[neededTileNumber]; GameObject tilecopy = Instantiate(thistile); tilecopy.name = levelNumberString + " " + levelPart + " tile " + ii.ToString(); tilecopy.AddComponent <CameraFrameData>(); CameraFrameData fd = tilecopy.GetComponent <CameraFrameData>(); fd.cameraFrame = neededFrameNumber; // Position the tile int actualpos = i; if (parallaxLayer) { tilecopy.transform.SetParent(parallaxParent.transform); } float tileCopyXPosition; if (parallaxLayer) { tileCopyXPosition = parallaxParent.transform.position.x + (actualpos * tileWidth); } else { tileCopyXPosition = actualpos * tileWidth; } tilecopy.transform.position = new Vector3(tileCopyXPosition, thistile.transform.position.y, tilecopy.transform.position.z); tilecopy.SetActive(true); // If we are the ground layer, then create the ground items, based on the // tile number as a seed. if (sortLayerName == "Ground") { // Random.InitState(levelManager.randomSeed + ii); int numFront = (int)Random.Range(2, 4); int numBack = (int)Random.Range(2, 4); addGroundDecorations(numFront, "GroundFront", tilecopy); addGroundDecorations(numBack, "GroundBack", tilecopy); // TODO: Change gems so that they are only created once per tile. int numGems = (int)Random.Range(0, 100); if (numGems < 20) { addGems(1, "Ground", tilecopy); } } // If we are the Proximate Background layer, attempt to attach clouds. if (sortLayerName == "BackgroundProximate") { int somenum = Random.Range(0, 100); if (somenum > 60) { GameObject skyObjectPrefab = Resources.Load("SkyObject") as GameObject; GameObject skyObject = Instantiate(skyObjectPrefab); skyObject.transform.position = new Vector2(tilecopy.transform.position.x, skyObject.transform.position.y); skyObject.SetActive(true); tilecopy.GetComponent <TileData>().attachedObjects.Add(skyObject); } int numBackgroundItems = (int)Random.Range(0, 3); //Random.InitState(ii*somenum); addBackgroundDecorations(numBackgroundItems, "BackgroundProximate", tilecopy); } // Keep a dicionary of active tiles activeTiles.Add(neededFrameNumber, tilecopy); } } }
public static Vector3 ComplementTranslate(CameraFrameData frame1, CameraFrameData frame2, Vector3 progress) { return(new Vector3(Lerp(frame1.CameraPosition.X, frame2.CameraPosition.X, progress.X), Lerp(frame1.CameraPosition.Y, frame2.CameraPosition.Y, progress.Y), Lerp(frame1.CameraPosition.Z, frame2.CameraPosition.Z, progress.Z))); }