(0.9.0) Another raycasting demo 19.12.2013

Showcase your libraries, tools and other projects that help your fellow love users.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: Another raycasting demo 13.10.2013

Post by jjmafiae »

is it possible to add basic 3d models in this thing?
User avatar
Jeeper
Party member
Posts: 611
Joined: Tue Mar 12, 2013 7:11 pm
Contact:

Re: Another raycasting demo 13.10.2013

Post 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.
Wojak
Party member
Posts: 134
Joined: Tue Jan 24, 2012 7:15 pm

Re: Another raycasting demo 13.10.2013

Post 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)
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: Another raycasting demo 13.10.2013

Post by jjmafiae »

is it possible to sell a raycasting game or is it a bit last year?
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Another raycasting demo 13.10.2013

Post 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.
Wojak
Party member
Posts: 134
Joined: Tue Jan 24, 2012 7:15 pm

Re: (0.9.0) Another raycasting demo 19.12.2013

Post 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
User avatar
guidedbycthulhu
Prole
Posts: 2
Joined: Wed Jan 15, 2014 3:39 am
Location: Ottawa, The City that Fun Forgot

Re: (0.9.0) Another raycasting demo 19.12.2013

Post 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.
Quinoa is a blight on mankind.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: (0.9.0) Another raycasting demo 19.12.2013

Post by jjmafiae »

We need oculus rift support for this!! xD
Water never stops
Prole
Posts: 1
Joined: Wed Feb 24, 2016 8:43 pm

Re: (0.9.0) Another raycasting demo 19.12.2013

Post by Water never stops »

How do you render floors, I'd like to see tutorial, thank you in advance.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests