mirror of
https://github.com/raylib-cs/raylib-cs
synced 2025-04-05 11:19:39 -04:00
Fixed VR issue
- Fixed werid graphical bug with VR. Issue was with the struct for VrDeviceInfo.
This commit is contained in:
parent
654d9c4347
commit
2e6a583193
@ -31,12 +31,18 @@
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Memory" Version="4.5.1" />
|
||||
</ItemGroup>
|
||||
|
@ -1,10 +1,7 @@
|
||||
// Raylib - https://github.com/raysan5/raylib/blob/master/src/raylib.h
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace Raylib
|
||||
{
|
||||
@ -371,10 +368,10 @@ namespace Raylib
|
||||
|
||||
public Color(int r, int g, int b, int a)
|
||||
{
|
||||
this.r = (byte)r;
|
||||
this.g = (byte)g;
|
||||
this.b = (byte)b;
|
||||
this.a = (byte)a;
|
||||
this.r = Convert.ToByte(r);
|
||||
this.g = Convert.ToByte(g);
|
||||
this.b = Convert.ToByte(b);
|
||||
this.a = Convert.ToByte(a);
|
||||
}
|
||||
|
||||
// extension to access colours from struct
|
||||
@ -569,7 +566,7 @@ namespace Raylib
|
||||
// public IntPtr locs;
|
||||
// [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.I1, SizeConst = Raylib.MAX_SHADER_LOCATIONS)]
|
||||
// [MarshalAs(UnmanagedType.ByValArray, SizeConst = Raylib.MAX_SHADER_LOCATIONS)]
|
||||
//[MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_I4)]
|
||||
// [MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_I4)]
|
||||
// public int[] locs;
|
||||
public fixed int locs[Raylib.MAX_SHADER_LOCATIONS];
|
||||
}
|
||||
@ -644,20 +641,21 @@ namespace Raylib
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public struct RayHitInfo
|
||||
{
|
||||
public bool hit
|
||||
{
|
||||
get { return Convert.ToBoolean(isHit); }
|
||||
set { isHit = Convert.ToByte(hit); }
|
||||
}
|
||||
|
||||
public byte isHit;
|
||||
public byte bHit;
|
||||
public float distance;
|
||||
public Vector3 position;
|
||||
public Vector3 normal;
|
||||
|
||||
// convert c bool(stored as byte) to bool
|
||||
public bool hit
|
||||
{
|
||||
get { return Convert.ToBoolean(bHit); }
|
||||
set { bHit = Convert.ToByte(hit); }
|
||||
}
|
||||
|
||||
public RayHitInfo(bool hit, float distance, Vector3 position, Vector3 normal)
|
||||
{
|
||||
this.isHit = Convert.ToByte(hit);
|
||||
this.bHit = Convert.ToByte(hit);
|
||||
this.distance = distance;
|
||||
this.position = position;
|
||||
this.normal = normal;
|
||||
@ -702,7 +700,7 @@ namespace Raylib
|
||||
|
||||
// Head-Mounted-Display device parameters
|
||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
|
||||
public struct VrDeviceInfo
|
||||
public unsafe struct VrDeviceInfo
|
||||
{
|
||||
public int hResolution;
|
||||
public int vResolution;
|
||||
@ -712,13 +710,15 @@ namespace Raylib
|
||||
public float eyeToScreenDistance;
|
||||
public float lensSeparationDistance;
|
||||
public float interpupillaryDistance;
|
||||
public float[] lensDistortionValues;
|
||||
public float[] chromaAbCorrection;
|
||||
public fixed float lensDistortionValues[4];
|
||||
public fixed float chromaAbCorrection[4];
|
||||
//public float[] lensDistortionValues;
|
||||
//public float[] chromaAbCorrection;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[SuppressUnmanagedCodeSecurity]
|
||||
//[SuppressUnmanagedCodeSecurity]
|
||||
public static partial class Raylib
|
||||
{
|
||||
#region Raylib-cs Variables
|
||||
@ -2202,92 +2202,9 @@ namespace Raylib
|
||||
public static extern void EndBlendMode();
|
||||
|
||||
// VR control functions
|
||||
// TODO: fix this, it's not using the original raylib dll function
|
||||
// Get VR device information for some standard devices
|
||||
//[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
//public static extern VrDeviceInfo GetVrDeviceInfo(int vrDeviceType);
|
||||
public static VrDeviceInfo GetVrDeviceInfo(VrDeviceType vrDeviceType)
|
||||
{
|
||||
VrDeviceInfo hmd = new VrDeviceInfo(); // Current VR device info
|
||||
|
||||
hmd.lensDistortionValues = new float[4];
|
||||
hmd.chromaAbCorrection = new float[4];
|
||||
|
||||
switch (vrDeviceType)
|
||||
{
|
||||
case VrDeviceType.HMD_DEFAULT_DEVICE:
|
||||
case VrDeviceType.HMD_OCULUS_RIFT_CV1:
|
||||
{
|
||||
// Oculus Rift CV1 parameters
|
||||
// NOTE: CV1 represents a complete HMD redesign compared to previous versions,
|
||||
// new Fresnel-hybrid-asymmetric lenses have been added and, consequently,
|
||||
// previous parameters (DK2) and distortion shader (DK2) doesn't work any more.
|
||||
// I just defined a set of parameters for simulator that approximate to CV1 stereo rendering
|
||||
// but result is not the same obtained with Oculus PC SDK.
|
||||
hmd.hResolution = 2160; // HMD horizontal resolution in pixels
|
||||
hmd.vResolution = 1200; // HMD vertical resolution in pixels
|
||||
hmd.hScreenSize = 0.133793f; // HMD horizontal size in meters
|
||||
hmd.vScreenSize = 0.0669f; // HMD vertical size in meters
|
||||
hmd.vScreenCenter = 0.04678f; // HMD screen center in meters
|
||||
hmd.eyeToScreenDistance = 0.041f; // HMD distance between eye and display in meters
|
||||
hmd.lensSeparationDistance = 0.07f; // HMD lens separation distance in meters
|
||||
hmd.interpupillaryDistance = 0.07f; // HMD IPD (distance between pupils) in meters
|
||||
hmd.lensDistortionValues[0] = 1.0f; // HMD lens distortion constant parameter 0
|
||||
hmd.lensDistortionValues[1] = 0.22f; // HMD lens distortion constant parameter 1
|
||||
hmd.lensDistortionValues[2] = 0.24f; // HMD lens distortion constant parameter 2
|
||||
hmd.lensDistortionValues[3] = 0.0f; // HMD lens distortion constant parameter 3
|
||||
hmd.chromaAbCorrection[0] = 0.996f; // HMD chromatic aberration correction parameter 0
|
||||
hmd.chromaAbCorrection[1] = -0.004f; // HMD chromatic aberration correction parameter 1
|
||||
hmd.chromaAbCorrection[2] = 1.014f; // HMD chromatic aberration correction parameter 2
|
||||
hmd.chromaAbCorrection[3] = 0.0f; // HMD chromatic aberration correction parameter 3
|
||||
|
||||
TraceLog((int)LogType.LOG_INFO, "Initializing VR Simulator (Oculus Rift CV1)");
|
||||
}
|
||||
break;
|
||||
case VrDeviceType.HMD_OCULUS_RIFT_DK2:
|
||||
{
|
||||
// Oculus Rift DK2 parameters
|
||||
hmd.hResolution = 1280; // HMD horizontal resolution in pixels
|
||||
hmd.vResolution = 800; // HMD vertical resolution in pixels
|
||||
hmd.hScreenSize = 0.14976f; // HMD horizontal size in meters
|
||||
hmd.vScreenSize = 0.09356f; // HMD vertical size in meters
|
||||
hmd.vScreenCenter = 0.04678f; // HMD screen center in meters
|
||||
hmd.eyeToScreenDistance = 0.041f; // HMD distance between eye and display in meters
|
||||
hmd.lensSeparationDistance = 0.0635f; // HMD lens separation distance in meters
|
||||
hmd.interpupillaryDistance = 0.064f; // HMD IPD (distance between pupils) in meters
|
||||
hmd.lensDistortionValues[0] = 1.0f; // HMD lens distortion constant parameter 0
|
||||
hmd.lensDistortionValues[1] = 0.22f; // HMD lens distortion constant parameter 1
|
||||
hmd.lensDistortionValues[2] = 0.24f; // HMD lens distortion constant parameter 2
|
||||
hmd.lensDistortionValues[3] = 0.0f; // HMD lens distortion constant parameter 3
|
||||
hmd.chromaAbCorrection[0] = 0.996f; // HMD chromatic aberration correction parameter 0
|
||||
hmd.chromaAbCorrection[1] = -0.004f; // HMD chromatic aberration correction parameter 1
|
||||
hmd.chromaAbCorrection[2] = 1.014f; // HMD chromatic aberration correction parameter 2
|
||||
hmd.chromaAbCorrection[3] = 0.0f; // HMD chromatic aberration correction parameter 3
|
||||
|
||||
TraceLog((int)LogType.LOG_INFO, "Initializing VR Simulator (Oculus Rift DK2)");
|
||||
}
|
||||
break;
|
||||
case VrDeviceType.HMD_OCULUS_GO:
|
||||
{
|
||||
// TODO: Provide device display and lens parameters
|
||||
break;
|
||||
}
|
||||
case VrDeviceType.HMD_VALVE_HTC_VIVE:
|
||||
{
|
||||
// TODO: Provide device display and lens parameters
|
||||
break;
|
||||
}
|
||||
case VrDeviceType.HMD_SONY_PSVR:
|
||||
{
|
||||
// TODO: Provide device display and lens parameters
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
|
||||
return hmd;
|
||||
}
|
||||
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern VrDeviceInfo GetVrDeviceInfo(int vrDeviceType);
|
||||
|
||||
// Init VR simulator for selected device parameters
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
@ -2475,8 +2392,20 @@ namespace Raylib
|
||||
public static extern AudioStream InitAudioStream(uint sampleRate, uint sampleSize, uint channels);
|
||||
|
||||
// Update audio stream buffers with data
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void UpdateAudioStream(AudioStream stream, short[] data, int samplesCount);
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl, EntryPoint = "UpdateAudioStream")]
|
||||
private static extern void UpdateAudioStreamInternal(AudioStream stream, IntPtr data, int samplesCount);
|
||||
|
||||
// Update audio stream buffers with data(byte)
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void UpdateAudioStream(AudioStream stream, ref byte[] data, int samplesCount);
|
||||
|
||||
// Update audio stream buffers with data(short)
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void UpdateAudioStream(AudioStream stream, ref short[] data, int samplesCount);
|
||||
|
||||
// Update audio stream buffers with data(float)
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void UpdateAudioStream(AudioStream stream, ref float[] data, int samplesCount);
|
||||
|
||||
// Close audio stream and free memory
|
||||
[DllImport(nativeLibName,CallingConvention = CallingConvention.Cdecl)]
|
||||
|
@ -26,11 +26,10 @@ public partial class core_vr_simulator
|
||||
int screenHeight = 600;
|
||||
|
||||
// NOTE: screenWidth/screenHeight should match VR device aspect ratio
|
||||
|
||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - vr simulator");
|
||||
|
||||
// Init VR simulator (Oculus Rift CV1 parameters)
|
||||
InitVrSimulator(GetVrDeviceInfo(HMD_OCULUS_RIFT_CV1));
|
||||
InitVrSimulator(GetVrDeviceInfo((int)HMD_OCULUS_RIFT_CV1));
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
Camera3D camera;
|
||||
|
@ -1,8 +1,5 @@
|
||||
using Raylib;
|
||||
using static Raylib.Raylib;
|
||||
using static Raylib.Model;
|
||||
using static Raylib.CameraMode;
|
||||
using System;
|
||||
|
||||
public enum LightType
|
||||
{
|
||||
@ -26,18 +23,8 @@ public struct Light
|
||||
public int colorLoc;
|
||||
}
|
||||
|
||||
|
||||
public partial class models_material_pbr
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************************
*
* raylib [models] example - PBR material
*
* This example has been created using raylib 1.8 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
|
||||
|
||||
public const int CUBEMAP_SIZE = 512;
|
||||
@ -124,7 +111,6 @@ public partial class models_material_pbr
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
return 0;
}
|
||||
|
||||
// Load PBR material (Supports: ALBEDO, NORMAL, METALNESS, ROUGHNESS, AO, EMMISIVE, HEIGHT maps)
|
||||
// NOTE: PBR shader is loaded inside this function
|
||||
unsafe public static Material LoadMaterialPBR(Color albedo, float metalness, float roughness)
|
||||
@ -262,5 +248,3 @@ public partial class models_material_pbr
|
||||
SetShaderValue(shader, light.colorLoc, diff, 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,13 +4,14 @@
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<ApplicationIcon>raylib-cs.ico</ApplicationIcon>
|
||||
<Platforms>AnyCPU;x64;x86</Platforms>
|
||||
<StartupObject>Test.NetCore.Program</StartupObject>
|
||||
<StartupObject>physics_demo</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<Optimize>false</Optimize>
|
||||
@ -18,6 +19,10 @@
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Bindings\Bindings.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -11,10 +11,15 @@
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Bindings\Bindings.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -46,6 +46,7 @@
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Optimize>false</Optimize>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
@ -56,6 +57,7 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@ -66,6 +68,7 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
|
Loading…
x
Reference in New Issue
Block a user