Page 3 of 3

Re: Another raycasting demo 13.10.2013

Posted: Sun Oct 13, 2013 10:51 pm
by jjmafiae
is it possible to add basic 3d models in this thing?

Re: Another raycasting demo 13.10.2013

Posted: Sun Oct 13, 2013 11:37 pm
by Jeeper
jjmafiae wrote:is it possible to add basic 3d models in this thing?
I would seriously recommend using an engine made for 3d if you want to use 3d models.

Re: Another raycasting demo 13.10.2013

Posted: Mon Oct 14, 2013 5:30 am
by Wojak
Jasoco wrote:What method did you use for the floors and ceilings?
I use the canvas method, the same You recommended me, but I've made some changes (I've mentioned this few post above), I've also replaced most of the hardcoded stuff with variables, changed the map format and texture loading code to make some stuff easier.
The most important code relating to floors and ceilings is in main.lua in setupfloor() function, the retexturing stuff is in texture_setup.lua in aplay() function.
jjmafiae wrote:is it possible to add basic 3d models in this thing?
This is not a full 3d, so no, but a good artist should be able to make sprites that look 3d (it will never be perfect though)

Re: Another raycasting demo 13.10.2013

Posted: Mon Oct 14, 2013 8:15 pm
by jjmafiae
is it possible to sell a raycasting game or is it a bit last year?

Re: Another raycasting demo 13.10.2013

Posted: Mon Oct 14, 2013 10:17 pm
by Jasoco
Wojak wrote:
jjmafiae wrote:is it possible to add basic 3d models in this thing?
This is not a full 3d, so no, but a good artist should be able to make sprites that look 3d (it will never be perfect though)
Eh, it's possible. Well, for me it's possible. These raycasting engines, if done the way I expect they are, have each column of the screen as a separate image sorted by distance from the camera, so using the same method I use for my 3D engine, I could totally merge the two engine types into one.

I'm just too lazy to prototype it.

One day.
jjmafiae wrote:is it possible to sell a raycasting game or is it a bit last year?
Not unless you bring something to the table worth purchasing.

GunGodz, a really well made FPS twitch shooter made by the guys who did Super Crate Box is free. Take that as you will. Also, Rogue-likes are a dime a dozen these days. But people still buy them. Then again they usually have a lot of polish.

Re: (0.9.0) Another raycasting demo 19.12.2013

Posted: Thu Dec 19, 2013 5:26 pm
by Wojak
This demo (raycast5) in now compatible with LÖVE 0.9.0 + a little bonus
(bonus include resizeable window and the raycasting code moved to scripts/raycasting.lua file)

Download in OP

Re: (0.9.0) Another raycasting demo 19.12.2013

Posted: Thu Jan 16, 2014 5:47 pm
by guidedbycthulhu
Not sure if either Wojak or Jasoco could make use of the following but...

With the release of Love 0.9, we've finally gotten the ability to use bitwise operators, as well as C data structures. This got me thinking, and I decided to revisit some old code.

Following "Sin and Cos - The Programmers Pals" http://www.helixsoft.nl/articles/circle/sincos.htm, I've quickly implemented an alternative floor/ceiling renderer. I've only been working with absurd resolutions (1280x720), but it's giving me a bit more oomf than the canvas method at that level.

Code: Select all

local bit = require("bit")
local ffi = require("ffi")
ffi.cdef[[
 typedef struct { uint8_t red, green, blue, alpha; } rgba_pixel;
]]
local sin = math.sin
local cos = math.cos
local abs = math.abs
local floor = math.floor

local renderX, renderY = 1280, 720
local textureWidth = 64
local destinationData = love.image.newImageData(renderX, renderY)
local destinationImage= love.graphics.newImage(destinationData)
local singleTile = love.graphics.newImage("tile.png")
local singleTileData = singleTile:getData()

function Raycaster:FastPixelFloor()
	local screenX, screenY
	local texX, texY
	local distance
	local lineDX, lineDY
	local spaceX, spaceY
	local mapX, mapY
	local maskX = textureWidth -1
	local maskY = textureWidth -1

	local pointerDestination = ffi.typeof("rgba_pixel *")	
	local pointerTile = ffi.typeof("rgba_pixel *")	

	local destinationArray = ffi.cast(pointerDestination , destinationData:getPointer())
	local tileArray = ffi.cast(pointerTile , singleTileData:getPointer())

	for screenY = renderY-1, renderY/2, -1 do		
		distance = renderY / (2.0 * screenY - renderY)
		distance = distance * textureWidth 
		
		horizontal_scale = (distance / renderY)
		
		lineDX = (-1 * sin(playerCamera.rot) * horizontal_scale)
		lineDY = (cos(playerCamera.rot) * horizontal_scale)

		spaceX = -playerCamera.x * textureWidth + (distance * cos(playerCamera.rot)) - renderX / 2 * lineDX
		spaceY = playerCamera.y * textureWidth + (distance * sin(playerCamera.rot)) - renderX / 2 * lineDY

		
		for screenX = 0, renderX-1, 1 do
			texX = floor(bit.band(spaceX, maskX))
			texY = floor(bit.band(spaceY, maskY))
			
			mapX = floor(abs(spaceX / 256))
			mapY = floor(abs(spaceY / 256))

			destinationArray[screenX + screenY * renderX] = tileArray[texX + texY * textureWidth ]
			destinationArray[screenX + (renderY-screenY) * renderX] = tileArray[texX + texY * textureWidth ]

			spaceX = spaceX + lineDX;
			spaceY = spaceY + lineDY;
		end	
	end
	destinationImage:refresh()
	love.graphics.setCanvas()	
	love.graphics.draw(destinationImage, 0, 0)
end
When running at 720p with the canvas method, I'm averaging 30-33fps on my office computer. Switching to the "FastPixelFloor" method, I'm able to get 39-41fps. Not a huge improvement or anything, but hey.

Somethings to note:
  • It should be possible to have multiple "heights" for these flats, simulating the tops of platforms or whatever.
  • This draws the entire floor/ceiling - very wasteful and could be optimized to only draw visible sections.
  • I tried loading a DLL containing a C version of "FastPixelFloor" - no noticeable difference over the LuaJIT version.

Re: (0.9.0) Another raycasting demo 19.12.2013

Posted: Thu Jan 16, 2014 6:08 pm
by jjmafiae
We need oculus rift support for this!! xD

Re: (0.9.0) Another raycasting demo 19.12.2013

Posted: Wed Feb 24, 2016 8:50 pm
by Water never stops
How do you render floors, I'd like to see tutorial, thank you in advance.