Add fixed in space and moveing example
This commit is contained in:
		
							parent
							
								
									7d516eb588
								
							
						
					
					
						commit
						223a6984cb
					
				
					 3 changed files with 102 additions and 9 deletions
				
			
		
							
								
								
									
										39
									
								
								fixedSpace/main.lua
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								fixedSpace/main.lua
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,39 @@
 | 
			
		|||
local width = 7
 | 
			
		||||
local height = 7
 | 
			
		||||
local distance = 5
 | 
			
		||||
 | 
			
		||||
function getHeadsetMatrix()
 | 
			
		||||
    local fx, fy, fz, fangle, fax, fay, faz = lovr.headset.getPose("head")
 | 
			
		||||
    return lovr.math.newMat4(lovr.math.vec3(fx, fy, fz), lovr.math.vec3(1, 1, 1), lovr.math.quat(fangle, fax, fay, faz))
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function drawGrid(pass, matrix)
 | 
			
		||||
 | 
			
		||||
	for i=-0.5,0.5,0.05 do
 | 
			
		||||
		local startVect = matrix*lovr.math.newVec3(width*-1, height*i, -distance)
 | 
			
		||||
		local endVect = matrix*lovr.math.newVec3(width*1, height*i, -distance)
 | 
			
		||||
		pass:line(startVect, endVect)
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	for i=-0.5,0.5,0.05 do
 | 
			
		||||
		local startVect = matrix*lovr.math.newVec3(width*i, height*-1, -distance)
 | 
			
		||||
		local endVect = matrix*lovr.math.newVec3(width*i, height*1, -distance)
 | 
			
		||||
		pass:line(startVect, endVect)
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function lovr.draw(pass)
 | 
			
		||||
	if headMatrix == nil then
 | 
			
		||||
		headMatrix = getHeadsetMatrix()
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	if headMatrix ~= nil then
 | 
			
		||||
 | 
			
		||||
		pass:setColor(0, 1, 0)
 | 
			
		||||
		drawGrid(pass, headMatrix)
 | 
			
		||||
 | 
			
		||||
		local center = headMatrix * lovr.math.newVec3(0.0, 0.0, -distance)
 | 
			
		||||
	pass:circle(center, 0.05, 0, 0, 0, 1, 'fill')
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										40
									
								
								moveing/main.lua
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								moveing/main.lua
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,40 @@
 | 
			
		|||
local width = 7
 | 
			
		||||
local height = 7
 | 
			
		||||
local distance = 5
 | 
			
		||||
local amplitude = 2
 | 
			
		||||
local x = 0
 | 
			
		||||
 | 
			
		||||
function getHeadsetMatrix()
 | 
			
		||||
    local fx, fy, fz, fangle, fax, fay, faz = lovr.headset.getPose("head")
 | 
			
		||||
    return lovr.math.newMat4(lovr.math.vec3(fx, fy, fz), lovr.math.vec3(1, 1, 1), lovr.math.quat(fangle, fax, fay, faz))
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function drawGrid(pass, headMatrix)
 | 
			
		||||
	local offset = math.sin(x)*amplitude
 | 
			
		||||
 | 
			
		||||
	for i=-0.5,0.5,0.05 do
 | 
			
		||||
		local startVect = headMatrix*lovr.math.newVec3(width*-1+offset, height*i, -distance)
 | 
			
		||||
		local endVect = headMatrix*lovr.math.newVec3(width*1+offset, height*i, -distance)
 | 
			
		||||
		pass:line(startVect, endVect)
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	for i=-0.5,0.5,0.05 do
 | 
			
		||||
		local startVect = headMatrix*lovr.math.newVec3(width*i+offset, height*-1, -distance)
 | 
			
		||||
		local endVect = headMatrix*lovr.math.newVec3(width*i+offset, height*1, -distance)
 | 
			
		||||
		pass:line(startVect, endVect)
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function lovr.draw(pass)
 | 
			
		||||
	local headMatrix = getHeadsetMatrix()
 | 
			
		||||
 | 
			
		||||
	x = x + 0.05
 | 
			
		||||
 | 
			
		||||
	pass:setColor(0, 1, 0)
 | 
			
		||||
	drawGrid(pass, headMatrix)
 | 
			
		||||
 | 
			
		||||
	local center = headMatrix * lovr.math.newVec3(math.sin(x)*amplitude, 0.0, -distance)
 | 
			
		||||
	pass:circle(center, 0.05, 0, 0, 0, 1, 'fill')
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1,22 +1,36 @@
 | 
			
		|||
local width = 20
 | 
			
		||||
local height = 20
 | 
			
		||||
local distance = 10
 | 
			
		||||
local width = 7
 | 
			
		||||
local height = 7
 | 
			
		||||
local distance = 5
 | 
			
		||||
local headMatrix
 | 
			
		||||
 | 
			
		||||
function getHeadsetMatrix()
 | 
			
		||||
    local fx, fy, fz, fangle, fax, fay, faz = lovr.headset.getPose("head")
 | 
			
		||||
    return lovr.math.newMat4(lovr.math.vec3(fx, fy, fz), lovr.math.vec3(1, 1, 1), lovr.math.quat(fangle, fax, fay, faz))
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function drawGrid(pass, headMatrix)
 | 
			
		||||
 | 
			
		||||
function drawGrid(pass)
 | 
			
		||||
	pass:setColor(0, 1, 0)
 | 
			
		||||
	for i=-0.5,0.5,0.05 do
 | 
			
		||||
		pass:line(width*-0.5, height*i, -distance, width*0.5, height*i, -distance)
 | 
			
		||||
		local startVect = headMatrix*lovr.math.newVec3(width*-1, height*i, -distance)
 | 
			
		||||
		local endVect = headMatrix*lovr.math.newVec3(width*1, height*i, -distance)
 | 
			
		||||
		pass:line(startVect, endVect)
 | 
			
		||||
	end
 | 
			
		||||
 | 
			
		||||
	for i=-0.5,0.5,0.05 do
 | 
			
		||||
		pass:line(width*i, height*-0.5, -distance, width*i, height*0.5, -distance)
 | 
			
		||||
		local startVect = headMatrix*lovr.math.newVec3(width*i, height*-1, -distance)
 | 
			
		||||
		local endVect = headMatrix*lovr.math.newVec3(width*i, height*1, -distance)
 | 
			
		||||
		pass:line(startVect, endVect)
 | 
			
		||||
	end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function lovr.draw(pass)
 | 
			
		||||
	local headMatrix = getHeadsetMatrix()
 | 
			
		||||
 | 
			
		||||
	drawGrid(pass)
 | 
			
		||||
	pass:circle(0, 0, -distance, 0.05, 0, 0, 0, 1, 'fill')
 | 
			
		||||
	pass:setColor(0, 1, 0)
 | 
			
		||||
	drawGrid(pass, headMatrix)
 | 
			
		||||
 | 
			
		||||
	local center = headMatrix * lovr.math.newVec3(0.0, 0.0, -distance)
 | 
			
		||||
	pass:circle(center, 0.05, 0, 0, 0, 1, 'fill')
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue