Re: Another raycasting demo 13.10.2013
Posted: Sun Oct 13, 2013 10:51 pm
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.jjmafiae wrote:is it possible to add basic 3d models in this thing?
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.Jasoco wrote:What method did you use for the floors and ceilings?
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 wrote:is it possible to add basic 3d models in this thing?
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.Wojak wrote: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 wrote:is it possible to add basic 3d models in this thing?
Not unless you bring something to the table worth purchasing.jjmafiae wrote:is it possible to sell a raycasting game or is it a bit last year?
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