Jump to content

VR enviroment


onaid
 Share

Recommended Posts

hi all, is the c++ version of leadwerks the only way to do VR ? or can i just change the mail lua .script to work with htc vive ?

 

like this ?

 

Enabling VR in your game could not be easier. Just use the Window::VRDisplay creation flag when you create your game's window, and you're done. Really, that's all it takes:

 

Window* window = Window::Create("My VR Game",0,0,1024,768,Window::Titlebar|Window::VRDisplay);
 

 

 

Or in Lua:

 

local window = Window:Create("My VR Game",0,0,1024,768,Window.Titlebar + Window.VRDisplay)

 

cheers 

Link to comment
Share on other sites

VR is not officially supported YET, but I am using it right now.  The advice above is from an old Oculus SDK implementation that was never released.

The way it works now is to just call VR::Enable() at the start of your program:

VR::Enable()

Or in Lua:

VR:Enable()

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Does that work with the Vive as well?

Mike

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 980 GTX with 16gb vram / SSD drives

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1060 GTX with 8gb vram / SSD drives

Alienware Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1070 Ti with 16gb vram / SSD drives

My Patreon page: https://www.patreon.com/michaelfelkercomposer

My music for sale: https://www.tgcstore.net/category/513?format=all&perpage=30&textures=undefined&price=all&order=default&artists[]=87213

Custom synths and sounds - http://www.supersynths.com

Link to comment
Share on other sites

	class VR//lua
	{
	public:
		static void HideWarning();//lua
		static Mat4 videomatrix;
		static Vec3 offset;
		static Mat4 hmdmatrix;

#ifndef BUILD_EDITOR
#ifndef __linux__
		static vr::IVRSystem* ivrsystem;
		static Buffer* eyebuffer;
		static GLuint videotexturehandle;
		static std::map<int, bool> buttonhitstate[vr::k_unMaxTrackedDeviceCount];
		static std::map<int, bool> buttondownstate[vr::k_unMaxTrackedDeviceCount];
		static std::map<int, bool> buttontouchstate[vr::k_unMaxTrackedDeviceCount];
		static std::map<int, Vec2> controlleraxisposition[vr::k_unMaxTrackedDeviceCount];
#endif
#endif
		static const int Left;//lua
		static const int Right;//lua
		static const int Roomspace;//lua
		static const int Seated;//lua
		static const int TouchpadButton;//lua
		static const int TriggerButton;//lua
		static const int GripButton;//lua
		static const int MenuButton;//lua
		static const int TouchpadAxis;//lua
		static const int TriggerAxis;//lua

#ifndef BUILD_EDITOR
#ifndef __linux__
		static std::map<int, Model*> devicemodel;
		static std::map<std::string, vr::RenderModel_t*> vrstockmodels;
		static std::map<int, vr::RenderModel_TextureMap_t*> vrstocktextures;
		static vr::EVRRenderModelError rendermodelerror;
		static char buffer[1024];
		static vr::VRControllerState_t controllerstate[vr::k_unMaxTrackedDeviceCount];
		static bool controllervalid[vr::k_unMaxTrackedDeviceCount];
		//static Vec2 controlleraxisposition[vr::k_unMaxTrackedDeviceCount][64];
		static Texture* CameraImage;
		static Bank* CameraImageData;
		static vr::TrackedCameraHandle_t TrackedCamera;
		static uint32_t lastFrameImage;
		static int controllerid[2];
#endif
#endif

		static void SetOffset(const Vec3& offset);//lua
		static void SetOffset(const float x, const float y, const float z);//lua
		static Vec3 GetOffset();//lua
		static bool Enable();//lua
		static void SetTrackingSpace(const int trackingspace);//lua
		static void CenterTracking();//lua
		static bool GetControllerButtonDown(const int id, const int button);//lua
		static bool GetControllerButtonTouched(const int id, const int button);//lua
		static bool GetControllerButtonHit(const int id, const int button);//lua
		static Vec2 GetControllerAxis(const int id, const int button);//lua
		static Model* GetControllerModel(const int id);//lua
		static bool EnableCamera();//lua
		static void DisableCamera();//lua
		static bool Enabled();//lua
		static Mat4 GetHMDMatrix();//lua
		static void TriggerHapticPulse(const int id);//lua

#ifndef BUILD_EDITOR
#ifndef __linux__

		static void UpdateTracking();
		static void UpdateCamera();
		static void Disable();
		static Model* LoadRenderModel(vr::RenderModel_t* rendermodel, vr::RenderModel_TextureMap_t* rendertexture);
#endif
#endif
	};

The haptic feedback stuff does not exist in the build you guys have but everything else is there, on Windows only at this time.  Works with Vive and reportedly with Oculus.

 

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Hey Josh, this is really great stuff. I started messing around with it this evening and drummed up the following VR controller. It's not complete, but maybe it'll help others get started. I'm stumped on how to change the HMD's base rotation to match a parent entity's though (very end of the code). I was trying to implement snap-turning. Also, just as a heads up, I'm testing with a Fove and it works great. I haven't tried it on my Rift yet.

Script.TrackingSpace = 0 --choice "Tracking Type" "Seated, Roomscale"
Script.CameraHeight  = 1.75 --float "Camera Height"
-- Maybe changing the FOV will stop items popping in and out at the edges
Script.PlayerFOV = 90.0 --float "Player FOV"
Script.MovementSpeed = 2.0 --float "Movement Speed"
Script.SnapTurn = true --bool "Use Snap Turning"
-- This is used when SnapTurn is true.
Script.TurnAngle = 30 --int "Snap Turn Angle"
-- This is used when SnapTurn is false.
Script.TurnSpeed = 1.0 --float "Smooth Turn Speed"

Script.Camera = nil

local vr_enabled = true
local actions = {}

function Script:InitializeActions()
	---------------------------------------
	-- Set this to false if you use QWERTY
	---------------------------------------
	local dvorak = true
	
	if dvorak then
		actions.move_forward = Key.Comma
		actions.move_back = Key.O
		actions.strafe_left = Key.A
		actions.strafe_right = Key.E
		actions.turn_left = Key.Quotes
		actions.turn_right = Key.Period
	else -- Assume QWERTY
		actions.move_forward = Key.W
		actions.move_back = Key.S
		actions.strafe_left = Key.A
		actions.strafe_right = Key.D
		actions.turn_left = Key.Q
		actions.turn_right = Key.E
	end
	
	actions.center_view = Key.Space
end

function Script:Start()
	self.InitializeActions()

	-- Add basic character properties
	self.entity:SetMass(1)
	self.entity:SetCollisionType(Collision.Character)
	self.entity:SetPhysicsMode(Entity.CharacterPhysics)
	
	-- Create the VR camera
	self.Camera = Camera:Create()
	self.Camera:SetParent(self.entity)
	self.Camera:SetFOV(self.PlayerFOV)
	self.Camera:SetPosition(Vec3(0, self.CameraHeight, 0))
	
	-- Enable VR
	if vr_enabled then
		VR:Enable()
		VR:SetTrackingSpace(self.TrackingSpace)
	end
end

function Script:UpdateWorld()
	self:CharacterMovement()
end

function Script:CharacterMovement()
	local forward = 0
	local strafe = 0
	local angle = 0
	
	if window:KeyDown(actions.move_forward) then forward = forward + 1 end
	if window:KeyDown(actions.move_back) then forward = forward - 1 end
	if window:KeyDown(actions.strafe_left) then strafe = strafe - 1 end
	if window:KeyDown(actions.strafe_right) then strafe = strafe + 1 end
	
	if self.SnapTurn then
		-- Use KeyHit() instead of KeyDown() to avoid continuous turning.
		if window:KeyHit(actions.turn_left) then angle = angle - self.TurnAngle end
		if window:KeyHit(actions.turn_right) then angle = angle + self.TurnAngle end 
	else
		if window:KeyDown(actions.turn_left) then angle = angle - self.TurnSpeed end
		if window:KeyDown(actions.turn_right) then angle = angle + self.TurnSpeed end
	end
	
	if window:KeyDown(actions.center_view) and vr_enabled then VR:CenterTracking() end
	
	forward = forward * self.MovementSpeed
	strafe = strafe * self.MovementSpeed
	
	local turn_angle = self.entity:GetRotation(true).y + angle
		
	self.entity:SetInput(turn_angle, forward, strafe)
	
	if vr_enabled then
		-- Set the HMD position to correspond to the parent entity.
		VR:SetOffset(self.entity:GetPosition(true) + Vec3(0.0, self.CameraHeight, 0.0))
		
		-- TODO: How do I adjust the HMD's base rotation? This doesn't seem to work.
		if angle ~= 0 then
			VR:CenterTracking()
		end
	end
end

 

Link to comment
Share on other sites

Ah, there is no way yet to rotate the HMD away from its true rotation, but there is a position offset you can use.  I supposed I could do the same thing for rotation.

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

41 minutes ago, pharoseer said:

No doubt! I hope more HMDs adopt that tech. I haven't been able to make use of it yet, but some of the demos I've tried have been pretty awesome. Being able to select targets by looking at them is really cool.

Your eye concentrates all your light receptors towards the center of your vision.  The image in the periphery of your vision is a lot more low-resolution.  If your entire eye had the same resolution as the center of your focus, your optic nerves would each be a foot in diameter.

So the resolution stuff they are talking about is 100% correct.

This would also allow a "real" field-of-view blur effect, which would be insane.

  • Upvote 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

My Alienware sitting in front of me has integrated eye tracking.  Can't wait to use it WITHOUT a headset.  I hate how confining the Vive is.

Mike

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 980 GTX with 16gb vram / SSD drives

MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1060 GTX with 8gb vram / SSD drives

Alienware Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1070 Ti with 16gb vram / SSD drives

My Patreon page: https://www.patreon.com/michaelfelkercomposer

My music for sale: https://www.tgcstore.net/category/513?format=all&amp;perpage=30&amp;textures=undefined&amp;price=all&amp;order=default&amp;artists[]=87213

Custom synths and sounds - http://www.supersynths.com

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...