// Update is called once per frame void Update() { if (RayFromCamera.ObjectLookAt() != null && teleport.CanTeleport) { //Debug.Log(Pose.GetLocalPosition(HandType).y + " " + Pose.GetVelocity(HandType).y); GameObject obj = RayFromCamera.ObjectLookAt(); //if (Pose.GetLocalPosition(HandType).y <= teleport.heightRequired && // (Pose.GetLastLocalPosition(HandType).y - Pose.GetLocalPosition(HandType).y) > 0 && // (Pose.GetLastVelocity(HandType).y - Pose.GetVelocity(HandType).y) > 0 && // Pose.GetVelocity(HandType).y <= teleport.speedRequired) //if((Pose.GetVelocity(HandType).y > 1 && Pose.GetLocalPosition(HandType).y > 0.1f) || Trigger.GetStateDown(SteamVR_Input_Sources.Any)) if (Pose.GetLocalPosition(HandType).y <= teleport.heightRequired && (Pose.GetLastLocalPosition(HandType).y - Pose.GetLocalPosition(HandType).y) > 0 && (Pose.GetLastVelocity(HandType).y - Pose.GetVelocity(HandType).y) > 0 && Pose.GetVelocity(HandType).y <= teleport.speedRequired) { teleport.Begin(obj); teleport.CanTeleport = false; } } //ShowTargetObject(); }
/// <summary> /// Checks the Tracker-Status and Updates the Position, Rotation and Velocity. /// </summary> protected override void UpdateTracker() { // Setting 'trackingOK' to false (In case we have an Error and return before the end of the method). trackingOK = false; // Check if OpenVR-System is found correctly. if (OpenVR.System == null) { Debug.LogError("<b>DHUI</b> | DroneTracking_Vive | OpenVR-System was not found."); return; } // If we didn't set the Action Pose. if (_VRTrackerActionPose == null) { // Check if there is an Active Action called "VRTracker". SteamVR_Action_Pose ap = SteamVR_Input.GetAction <SteamVR_Action_Pose>("VRTracker"); if (ap.GetActive(SteamVR_Input_Sources.Any)) { _VRTrackerActionPose = ap; droneTrackerIndex = _VRTrackerActionPose.GetDeviceIndex(SteamVR_Input_Sources.Any); } else { Debug.LogError("<b>DHUI</b> | DroneTracking_Vive | No Active VR-Tracker was found."); return; } } // Copy Position and Rotation to the 'trackedTransform' and save the Velocity. // If 'trackTransformAsLocal' is true: Copy the real tracked pose to 'trackedTransform' as localPosition & localRotation if (trackTransformAsLocal) { trackedTransform.localPosition = _VRTrackerActionPose.GetLocalPosition(SteamVR_Input_Sources.Any) - trackerToDroneOffset_Position; trackedTransform.localRotation = _VRTrackerActionPose.GetLocalRotation(SteamVR_Input_Sources.Any) * Quaternion.Euler(trackerToDroneOffset_Rotation); } // If 'trackTransformAsLocal' is false (= default): Copy the real tracked pose to 'trackedTransform' as (global) position & rotation else { trackedTransform.position = _VRTrackerActionPose.GetLocalPosition(SteamVR_Input_Sources.Any) - trackerToDroneOffset_Position; trackedTransform.rotation = _VRTrackerActionPose.GetLocalRotation(SteamVR_Input_Sources.Any) * Quaternion.Euler(trackerToDroneOffset_Rotation); } velocity = _VRTrackerActionPose.GetVelocity(SteamVR_Input_Sources.Any); // Calculate the current pose for our device. [See https://github.com/ValveSoftware/openvr/wiki/IVRSystem::GetDeviceToAbsoluteTrackingPose] TrackedDevicePose_t[] trackedDevicePoses = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount]; OpenVR.System.GetDeviceToAbsoluteTrackingPose(ETrackingUniverseOrigin.TrackingUniverseStanding, 0.0f, trackedDevicePoses); TrackedDevicePose_t droneTrackedDevicePose = trackedDevicePoses[droneTrackerIndex]; // If the 'TrackedDevicePose' of the drone is valid, connected and running ok, we can set the 'trackingOK' to true. if (droneTrackedDevicePose.bPoseIsValid && droneTrackedDevicePose.bDeviceIsConnected && droneTrackedDevicePose.eTrackingResult == ETrackingResult.Running_OK) { trackingOK = true; } }
// Update is called once per frame void Update() { if (trigger.GetStateDown(rightHand)) { CreateLine(); } if (trigger.GetState(rightHand)) { Vector3 pos = pose.GetLocalPosition(rightHand); ++line.positionCount; line.SetPosition(line.positionCount - 1, pos); } }
// Update is called once per frame void Update() { if (trigger.GetStateDown(rightHand)) { CreateLineObject(); } if (trigger.GetState(rightHand)) { Vector3 pos = /*transform.parent.position +*/ pose.GetLocalPosition(rightHand); // 라인의 노드 갯수 증가 line.positionCount++; line.SetPosition(line.positionCount - 1, pos); } }
void Update() { // if (trigger.GetStateDown(rightHand)) { CreateLineObject(); } // if (trigger.GetState(rightHand)) { Vector3 pos = pose.GetLocalPosition(rightHand); //라인의 노드 갯수 증가 line.positionCount++; line.SetPosition(line.positionCount - 1, pos); } }
void Update() { Position = pose.GetLocalPosition(inputSource); Stick.Value = stick.GetAxis(inputSource); MainButtonPressed.Value = mainButton.GetState(inputSource); ModifierPressed.Value = modifier.GetState(inputSource); CancellerPressed.Value = canceller.GetState(inputSource); }
public bool IsControllerWorking() { Vector3 pos = position.GetLocalPosition(handType); if (pos == null || pos.Equals(Vector3.zero)) { return(false); } return(true); }
private void SetMoveDirection() { Vector3 right = PoseRightFoot.GetLocalPosition(RightFoot); Vector3 left = PoseLeftFoot.GetLocalPosition(LeftFoot); rightFoot = new Vector2(right.x, right.z); leftFoot = new Vector2(left.x, left.z); footDirection = (rightFoot - leftFoot).normalized; moveDirection = footDirection; }
void CreateLineObject() { //"Line"이라는 게임오브젝트를 생성하여 LineRenderer컴포넌트를 추가한다. GameObject lineObject = new GameObject("Line"); line = lineObject.AddComponent <LineRenderer>(); lineCol = lineObject.AddComponent <SphereCollider>(); //번개효과 머티리얼 테스트중(박동건)/////////////////////////// //Material newMat = GetComponent<LineRenderer>().material; //newMat.SetFloat("_StartSeed", Random.value * 1000); //GetComponent<LineRenderer>().material = newMat; /////////////////////////////////////////////////////////////// //라인렌더러에 연결할 머티리얼 생성 Material mt = new Material(Shader.Find("Unlit/Color")); mt.color = lineColor; line.material = mt; line.useWorldSpace = false; //라인의 끝부분을 부드럽게 하기위한 버텍스 갯수 설정 line.numCapVertices = 20; //라인렌더러의 폭 설정 line.widthMultiplier = 0.1f; line.startWidth = lineWidth; line.endWidth = lineWidth; //라인렌더러의 노드 갯수를 1로 설정 line.positionCount = 1; //첫 번째 노드의 위치를 컨트롤러의 위치로 설정 Vector3 position = pose.GetLocalPosition(rightHand); line.SetPosition(0, position); }
// Update is called once per frame void Update() { Vector3 pos = Poser.GetLocalPosition(source); Quaternion rot = Poser.GetLocalRotation(source); // Move rocket when thrust is active float thrust = Engine_manager.g_ThrustLevel; if (thrust > 0.0f) { pos += (transform.localRotation * Vector3.forward) * 2.0f * thrust; } float rotSpeed = 0.6f; transform.localRotation = Quaternion.Slerp(transform.localRotation, rot, rotSpeed * Time.deltaTime); float movSpeed = 0.8f; transform.localPosition = Vector3.Slerp(transform.localPosition, pos, movSpeed * Time.deltaTime); }
private void handlePose() { if (debugPoseMarkerStart != null && poseAction.GetActive(_controller)) { Vector3 posePos = poseAction.GetLocalPosition(_controller); debugPoseMarkerStart.transform.localPosition = posePos; LineRenderer line = debugPoseMarkerStart.GetComponent <LineRenderer>(); line.transform.position = debugPoseMarkerStart.transform.position; if (line != null) { line.SetPosition(0, debugPoseMarkerStart.transform.position); line.transform.localRotation = poseAction.GetLocalRotation(_controller); RaycastHit hit; // Shorten the default magnitude of the beam by 0.3 Vector3 direction = poseAction.GetLocalRotation(_controller) * vectorFoward * 0.3f; Vector3 endPoint = line.transform.position + direction * 10000; line.SetPosition(1, endPoint); debugPoseMarkerEnd.transform.position = endPoint; Ray ray = new Ray(line.transform.position, direction); if (Physics.Raycast(ray, out hit)) { //Debug.Log("Hit!"); debugPoseMarkerEnd.transform.position = hit.point; line.SetPosition(1, hit.point); handleHit(hit); } else { //Debug.Log("Missed!"); //line.SetPosition(1, line.transform.position + direction * 10000); //debugPoseMarkerEnd.transform.position = line.transform.position + direction * 10000; handleMiss(); } } } }
public Vector3 DifferenceLocalPosition() { return(pose.GetLocalPosition(handType) - pose.GetLastLocalPosition(handType)); }
// Update is called once per frame void Update() { Vector3 tracker_position = trackerPose.GetLocalPosition(trackerSource); print(tracker_position); }
// Update is called once per frame void Update() { // Adapted from: http://3dcognition.com/unity-flight-simulator-phase-2/ // and http://wiki.unity3d.com/index.php/SmoothMouseLook if (ResetButton.GetState(SteamVR_Input_Sources.Any)) { Reset(); } float altitude = transform.position.magnitude; float rotateSpeed = 30.0f; // degrees/second float speed = 0.5f * (altitude - 0.99f); // WASD movement, earth radius/second float mouseSpeed = 140.0f; // degrees rotation per pixel of mouse movement / second float transAmount = speed * Time.deltaTime; float rotateAmount = rotateSpeed * Time.deltaTime; // Update time zooming if (Input.GetKeyDown(".")) { TimeControl.ui_timelapse *= 4.0f; } if (Input.GetKeyDown(",")) { TimeControl.ui_timelapse /= 4.0f; } if (Input.GetKeyDown("/")) { TimeControl.ui_timelapse = 1.0f; } // Debug.Log("Orbital camera vive running"); float zoom = TimeZoomAxis.GetAxis(TimeHand); if (zoom > 0.0f) { Debug.Log(" time axis active: " + zoom); TimeControl.ui_timelapse = 16.0f * Mathf.Pow(4.0f, 1.0f + 2.0f * zoom); } else { TimeControl.ui_timelapse = 1.0f; } TimeControl.Update(); float rotX = 0.0f; float rotY = 0.0f; if (Input.GetMouseButton(0)) { rotX += Input.GetAxis("Mouse X") * mouseSpeed * Time.deltaTime; rotY -= Input.GetAxis("Mouse Y") * mouseSpeed * Time.deltaTime; } if (Input.GetKey("up")) { rotY += rotateAmount; } if (Input.GetKey("down")) { rotY -= rotateAmount; } if (Input.GetKey("left")) { rotX -= rotateAmount; } if (Input.GetKey("right")) { rotX += rotateAmount; } Vector3 rocket = new Vector3(0.0f, 0.0f, 0.0f); float rocketAccel = 50.0f; // m/s^2 acceleration in vacuum if (Input.GetKey("a")) { rocket.x = -rocketAccel; } if (Input.GetKey("d")) { rocket.x = +rocketAccel; } if (Input.GetKey("z")) { rocket.y = -rocketAccel; } if (Input.GetKey("q")) { rocket.y = +rocketAccel; } if (Input.GetKey("s")) { rocket.z = -rocketAccel; } if (Input.GetKey("w")) { rocket.z = +rocketAccel; } // Rotate keyboard rocket thrust to match local motion frame rocket = rocket.x * transform.right + rocket.y * transform.up + rocket.z * transform.forward; float thrust = RocketThrustAxis.GetAxis(RocketHand); Quaternion rot = RocketPose.GetLocalRotation(RocketHand); rot = transform.rotation * rot; // local to world rotation Vector3 rocketForward = rot * Vector3.forward; if (thrust > 0.0f) { Debug.Log(" thrust axis active: " + thrust + " direction " + rocketForward); rocket += thrust * rocketForward * rocketAccel; // FIXME: rotate to match controller orientation Engine_manager.g_ThrustLevel = thrust; } else { Engine_manager.g_ThrustLevel = 0.0f; } float me = 5.972e24f; // mass of Earth, in kilograms float G = 6.67408e-11f; // gravitational constant, MKS units float r = P.magnitude; // distance to spacecraft, in meters float accel = -G * me / (r * r); // scalar acceleration due to gravity (m/s^2) Vector3 A = P * (accel / P.magnitude); // vector acceleration due to gravity A += rocket; // acceleration due to rocket float dt = Time.deltaTime * TimeControl.timelapse; V = V + dt * A; // Euler update for velocity P = P + dt * V; // Euler update for position float height = (P.magnitude - Re) / (km); // kilometers altitude float airdrag = 0.0f; if (height < 60.0f) { float air_density = Mathf.Exp(-height / 8.0f); float dragfactor = 0.01f + 0.2f * Vector3.Cross(rocketForward.normalized, V.normalized).magnitude; airdrag = dragfactor * air_density; float dragloss = (1.0f - airdrag * dt); if (dragloss < 0.5f) { dragloss = 0.5f; } V = V * dragloss; airdrag *= V.magnitude; } float min_altitude = 1.00001f * Re; // stay outside of the planet if (P.magnitude < min_altitude) { P = P * (min_altitude / P.magnitude); } float max_altitude = 100.0f * Re; // stay fairly near the planet if (P.magnitude > max_altitude) { P = P * (max_altitude / P.magnitude); V = V * 0.001f; } // Bake output camera position Vector3 pos = P * (1.0f / km);// copy out simulated position to GUI position (in Earth radii) //pos.y-=1.8f; // make up for user height transform.position = pos; transform.Rotate(rotY, rotX, 0); // Update the text readout gizmo var TimeReadout = GameObject.FindWithTag("TimeReadout"); if (TimeReadout) { TimeReadout.transform.localPosition = TimePose.GetLocalPosition(TimeHand); TimeReadout.transform.localRotation = TimePose.GetLocalRotation(TimeHand); } var TextReadout = GameObject.FindWithTag("TimeReadoutText"); if (TextReadout) { float alt = (P.magnitude - Re) / km; float vel = V.magnitude / km; string pre = ""; if (airdrag > 0.0) { pre = "Air drag: " + string.Format("{0:F1}", airdrag) + " m/s/s\n"; } string text = pre + "Time: x" + string.Format("{0:F1}", TimeControl.timelapse) + "\n" + "Thrust: " + string.Format("{0:F0}", rocket.magnitude) + " m/s/s\n" + "Speed: " + string.Format("{0:F2}", vel) + " km/s\n" + "Vertical: " + string.Format("{0:F2}", Vector3.Dot(P.normalized, V) / km) + " km/s\n" + "Altitude: " + (int)alt + " km"; TextReadout.GetComponent <TextMesh>().text = text; } if (Input.GetKey("x") || Input.GetKey("escape")) { Application.Quit(); } }
void FixedUpdate() { /*// Swing Climbing * if (leftHand.canSwingGrip && GetGrap(leftHand.hand)) { * attachPlayer(leftHand.swing); * leftHand.swing.GetComponent<Rigidbody>().useGravity = true; * } * else if (leftHand.canGrip && GetGrapUp(leftHand.hand, lastLeftGrap)) { * detachPlayer(leftHand.swing); * leftHand.swing.GetComponent<Rigidbody>().useGravity = false; * }*/ // Normal Climbing // tests if a hand is still grabbed onto an object if (isGrappedLeft || isGrappedRight) { isGrapped = true; } else { isGrapped = false; } if (!isGrapped) { body.useGravity = true; } // LeftHand if (leftHand.canGrip && GetGrap(leftHand.hand)) { // change to grab physics body.velocity = Vector3.zero; body.useGravity = false; isGrappedLeft = true; // calc grab position body.transform.position += (leftHand.previousPosition - handPosition.GetLocalPosition(leftHand.hand.handType)); } else if (leftHand.canGrip && GetGrapUp(leftHand.hand, lastLeftGrap)) { // change to normal physics body.useGravity = true; isGrappedLeft = false; // calc fling velocity body.velocity = (leftHand.previousPosition - handPosition.GetLocalPosition(leftHand.hand.handType)) / Time.deltaTime; } else // has to be here because Hand can lose grap without letting go { isGrappedLeft = false; } // RightHand if (rightHand.canGrip && GetGrap(rightHand.hand)) { // change to grab physics body.velocity = Vector3.zero; body.useGravity = false; isGrappedRight = true; // calc grab position body.transform.position += (rightHand.previousPosition - handPosition.GetLocalPosition(rightHand.hand.handType)); } else if (rightHand.canGrip && GetGrapUp(rightHand.hand, lastRightGrap)) { // change to normal physics body.useGravity = true; isGrappedRight = false; // calc fling velocity body.velocity = (rightHand.previousPosition - handPosition.GetLocalPosition(rightHand.hand.handType)) / Time.deltaTime; } else // has to be here because Hand can lose grap without letting go { isGrappedRight = false; } // set last grap power lastLeftGrap = grapAction.GetAxis(leftHand.hand.handType); lastRightGrap = grapAction.GetAxis(rightHand.hand.handType); // set previous position leftHand.previousPosition = handPosition.GetLocalPosition(leftHand.hand.handType); rightHand.previousPosition = handPosition.GetLocalPosition(rightHand.hand.handType); }
private void OnPoseChanged(SteamVR_Action_Pose actionIn, SteamVR_Input_Sources hand) { transform.position = actionIn.GetLocalPosition(hand); transform.rotation = actionIn.GetLocalRotation(hand); }
// Update is called once per frame void FixedUpdate() { if (vehicle) { // Apply keyboard motor and steering controls throttle = throttleAction.GetAxis(throttleSource); brake = brakeAction.GetAxis(brakeSource); vehicle.complementary_filter(0.1f, ref vehicle.cur_motor_power, throttle - brake); Vector3 headPos = headPoser.GetLocalPosition(headSource); localHead = headPos; Quaternion headRot = headPoser.GetLocalRotation(headSource); // Slightly bank the user's head during turns, // so the real gravity vector lines up with apparent acceleration. // Disadvantage: mismatch in user's roll gyros. vehicle.complementary_filter(0.1f, ref bank, vehicle.centripital); if (BankingTurns) // Apply the turn // Reset full transform { BankingTurns.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, 0.0f); BankingTurns.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f); // Rotate around the user's head position worldHead = BankingTurns.transform.TransformPoint(headPos); Vector3 axis = BankingTurns.transform.forward; // vehicle.last_velocity; axis.y = 0.0f; BankingTurns.transform.RotateAround(worldHead, axis, -30.0f * bank); } Vector3 framePos = framePoser.GetLocalPosition(frameSource); Quaternion frameRot = framePoser.GetLocalRotation(frameSource); if (VRAreaOffset && !setupVRArea && framePos.x != 0.0f) { // Locate VR camera relative to the physical frame: // SteamVR does wacky things with the initial camera position, // putting 0,0,0 as the center of the Steam VR room area. VRAreaOffset.transform.localPosition = new Vector3(-framePos.x, -framePos.y + 1.05f - 0.4f, -framePos.z + 0.7f); setupVRArea = true; } // Plant rollcage relative to the physical frame rollcage.transform.localPosition = framePos + new Vector3(0.0f, -0.5f, -1.0f); rollcage.transform.localRotation = frameRot * Quaternion.Euler(-60.0f, 180.0f, 0.0f); handlebars.transform.localPosition = framePos + new Vector3(0.0f, -0.2f, -0.10f); Vector3 steerPos = steerPoser.GetLocalPosition(steerSource); Quaternion steerRot = steerPoser.GetLocalRotation(steerSource); steerQuat = steerRot * Quaternion.Inverse(frameRot); float angle = 0.0f; steerQuat.ToAngleAxis(out angle, out steerAxis); if (Mathf.Abs(steerAxis.y) > 0.7f) // we're in a reasonable steering configuration { steer = angle; if (steerQuat.w > 0.0f) { steer = -angle; } if (steer > 180.0f) { steer -= 360.0f; // rotation is around zero } steer = -steer; steer -= 30.0f; // baked-in rotation offset (steering trim) vehicle.complementary_filter(0.1f, ref vehicle.cur_steer, steer / 45.0f); handlebars.transform.localRotation = frameRot * Quaternion.Euler(-90.0f, 180.0f, 0.0f) * Quaternion.Euler(0.0f, steer, 0.0f); } } }
// Update is called once per frame void Update() { transform.position = Pose.GetLocalPosition(SteamVR_Input_Sources.LeftHand); }