Skip to content

Commit

Permalink
Merge pull request #15 from Vivero/updated-openvr
Browse files Browse the repository at this point in the history
Support KSP v1.4
  • Loading branch information
Vivero authored Mar 9, 2018
2 parents 95cb1eb + df5684d commit d6994cd
Show file tree
Hide file tree
Showing 36 changed files with 6,925 additions and 944 deletions.
74 changes: 55 additions & 19 deletions KerbalVR/KerbalVR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KerbalVR</RootNamespace>
<AssemblyName>KerbalVR</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -92,30 +93,65 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="KerbalVRPlugin.cs" />
<Compile Include="MathUtils.cs" />
<Compile Include="openvr_api.cs" />
<Compile Include="KerbalVR_MathUtils.cs" />
<Compile Include="KerbalVR_Plugin.cs" />
<Compile Include="KerbalVR_Utils.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SteamVR.cs" />
<Compile Include="SteamVR_Utils.cs" />
<Compile Include="SteamVR\Plugins\openvr_api.cs" />
<Compile Include="SteamVR\Scripts\SteamVR.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_Camera.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_CameraFlip.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_CameraMask.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_Controller.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_ControllerManager.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_Ears.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_Events.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_ExternalCamera.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_Fade.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_Frustum.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_GameView.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_IK.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_LoadLevel.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_Menu.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_Overlay.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_PlayArea.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_Render.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_RenderModel.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_Skybox.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_SphericalProjection.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_Stats.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_TestController.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_TrackedCamera.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_TrackedObject.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_UpdatePoses.cs" />
<Compile Include="SteamVR\Scripts\SteamVR_Utils.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>if $(PlatformName) == x86 (
copy /Y "$(TargetPath)" C:\KSP_win\GameData\KerbalVR\
copy /Y "$(ProjectDir)"\lib\win32\openvr_api.dll C:\KSP_win\
) ELSE (
copy /Y "$(TargetPath)" C:\KSP_win64\GameData\KerbalVR\
copy /Y "$(ProjectDir)"\lib\win64\openvr_api.dll C:\KSP_win64\
<PostBuildEvent>mkdir "$(TargetDir)rel\GameData\KerbalVR\openvr"

copy /Y "$(TargetDir)"\"$(TargetFileName)" "$(TargetDir)\rel\GameData\KerbalVR\"

copy /Y "$(SolutionDir)"\LICENSE "$(TargetDir)\rel\"

copy /Y "$(SolutionDir)\README.md" "$(TargetDir)\rel\"

robocopy "$(ProjectDir)lib" "$(TargetDir)\rel\GameData\KerbalVR\openvr" /E



if $(PlatformName) == x64 (

robocopy "$(TargetDir)\rel\GameData\KerbalVR" "C:\KSP_win64\GameData\KerbalVR" /E

)

else (
robocopy "$(TargetDir)\rel\GameData\KerbalVR" "C:\KSP_win\GameData\KerbalVR" /E

)

mkdir "$(TargetDir)"\rel\GameData\KerbalVR\
mkdir "$(TargetDir)"\rel\openvr
copy /Y "$(TargetDir)"\"$(TargetFileName)" "$(TargetDir)"\rel\GameData\KerbalVR\
copy /Y "$(SolutionDir)"\LICENSE "$(TargetDir)"\rel\
copy /Y "$(SolutionDir)"\README.md "$(TargetDir)"\rel\
robocopy "$(ProjectDir)\lib" "$(TargetDir)\rel\openvr" /E
copy /Y "$(ProjectDir)"\LICENSE-openvr "$(TargetDir)"\rel\openvr</PostBuildEvent>
copy /Y "$(ProjectDir)\LICENSE-openvr" "$(TargetDir)\rel\openvr"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
27 changes: 8 additions & 19 deletions KerbalVR/MathUtils.cs → KerbalVR/KerbalVR_MathUtils.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine;
using Valve.VR;

namespace KerbalVR
{
class MathUtils
public class MathUtils
{
/// <summary>
/// Converts a pose matrix provided by OpenVR to a set of Euler angles, in radians.
/// </summary>
/// <param name="poseMatrix">OpenVR pose matrix</param>
/// <returns>Vector3 containing [pitch, yaw, roll] (in radians).</returns>
public static Vector3 PoseMatrix2RotationEuler(ref HmdMatrix34_t poseMatrix)
{
public static Vector3 PoseMatrix2RotationEuler(ref HmdMatrix34_t poseMatrix) {
Vector2 vector_r32_r33 = new Vector2(poseMatrix.m9, poseMatrix.m10);
float eulerPitch = Mathf.Atan2(poseMatrix.m9, poseMatrix.m10);
float eulerYaw = Mathf.Atan2(-poseMatrix.m8, vector_r32_r33.magnitude);
Expand All @@ -29,8 +23,7 @@ public static Vector3 PoseMatrix2RotationEuler(ref HmdMatrix34_t poseMatrix)
/// </summary>
/// <param name="poseMatrix">OpenVR pose matrix</param>
/// <returns>Quaternion representing the pose matrix rotation.</returns>
public static Quaternion PoseMatrix2RotationQuaternion(ref HmdMatrix34_t poseMatrix)
{
public static Quaternion PoseMatrix2RotationQuaternion(ref HmdMatrix34_t poseMatrix) {
// Adapted from: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
Quaternion q = new Quaternion();
q.w = Mathf.Sqrt(Mathf.Max(0, 1 + poseMatrix.m0 + poseMatrix.m5 + poseMatrix.m10)) / 2;
Expand All @@ -48,8 +41,7 @@ public static Quaternion PoseMatrix2RotationQuaternion(ref HmdMatrix34_t poseMat
/// </summary>
/// <param name="poseMatrix">OpenVR pose matrix</param>
/// <returns>Vector3 with [x,y,z] position of pose matrix.</returns>
public static Vector3 PoseMatrix2Position(ref HmdMatrix34_t poseMatrix)
{
public static Vector3 PoseMatrix2Position(ref HmdMatrix34_t poseMatrix) {
return new Vector3(poseMatrix.m3, poseMatrix.m7, poseMatrix.m11);
}

Expand All @@ -59,8 +51,7 @@ public static Vector3 PoseMatrix2Position(ref HmdMatrix34_t poseMatrix)
/// <param name="poseMatrix">OpenVR pose matrix</param>
/// <param name="position">Output position vector</param>
/// <param name="rotation">Output rotation vector [pitch, yaw, roll] in radians</param>
public static void PoseMatrix2PositionAndRotation(ref HmdMatrix34_t poseMatrix, ref Vector3 position, ref Vector3 rotation)
{
public static void PoseMatrix2PositionAndRotation(ref HmdMatrix34_t poseMatrix, ref Vector3 position, ref Vector3 rotation) {
// return position
position = PoseMatrix2Position(ref poseMatrix);

Expand All @@ -74,17 +65,15 @@ public static void PoseMatrix2PositionAndRotation(ref HmdMatrix34_t poseMatrix,
/// <param name="poseMatrix">OpenVR pose matrix</param>
/// <param name="position">Output position vector</param>
/// <param name="rotation">Output rotation quaternion</param>
public static void PoseMatrix2PositionAndRotation(ref HmdMatrix34_t poseMatrix, ref Vector3 position, ref Quaternion rotation)
{
public static void PoseMatrix2PositionAndRotation(ref HmdMatrix34_t poseMatrix, ref Vector3 position, ref Quaternion rotation) {
// return position
position = PoseMatrix2Position(ref poseMatrix);

// return rotation
rotation = PoseMatrix2RotationQuaternion(ref poseMatrix);
}

public static Matrix4x4 Matrix4x4_OpenVr2UnityFormat(ref HmdMatrix44_t mat44_openvr)
{
public static Matrix4x4 Matrix4x4_OpenVr2UnityFormat(ref HmdMatrix44_t mat44_openvr) {
Matrix4x4 mat44_unity = Matrix4x4.identity;
mat44_unity.m00 = mat44_openvr.m0;
mat44_unity.m01 = mat44_openvr.m1;
Expand Down
Loading

0 comments on commit d6994cd

Please sign in to comment.