Working Raycasting example! WolfenLöve 3D if you will...

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Working Raycasting example! WolfenLöve 3D if you will...

Post by coffee »

Jasoco wrote: Got some new friends to keep me company.
I would be afraid of friends like that even having a peaceful look. Are you sure they aren't instead stalkers? :)
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Working Raycasting example! WolfenLöve 3D if you will...

Post by Robin »

Nice! Your "friends" look creepy, though. :P
Help us help you: attach a .love.
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Working Raycasting example! WolfenLöve 3D if you will...

Post by Jasoco »

No more creepy than having a disguised Nazi member following you around. I haven't ported in the AI code yet so they just follow the player. I haven't even drawn other angles yet so it would be useless to do it now anyway. There's a lot to finish here. I'm terrible enough as it is drawing people.
User avatar
richapple
Citizen
Posts: 65
Joined: Sun Dec 25, 2011 10:25 am

Re: Working Raycasting example! WolfenLöve 3D if you will...

Post by richapple »

You promised to add mouselook after you finish doors :(
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Working Raycasting example! WolfenLöve 3D if you will...

Post by Jasoco »

Hold your horse, Captain! There's a lot to do. I can only do so much at once. Plus I have other things like work and recording Let's Plays on the blatant whoring of my YouTune channel spam spam spammity spam watch them spam.
Gravy
Citizen
Posts: 80
Joined: Sun Jan 22, 2012 10:15 pm
Location: CA, USA

Re: Working Raycasting example! WolfenLöve 3D if you will...

Post by Gravy »

Hi all,

I'm also working a game that uses a modified version jfroco's raycasting example. However, I just added in textures and now have severe framerate issues. How are you guys drawing in the textures? I'm basically just pulling pixel by pixel out of the image and drawing a rectangle that color. I have messed around with commenting things out and fixing values, and it seems like the line that actually draws the rectangles is the culprit (love.graphics.rectangle("fill", rayScreenPos,i,stripWidth, 2)).

Code: Select all

function drawStrip(stripIdx,height,vHit, textureX)
	local rayScreenPos = stripIdx * stripWidth;
	local tempw =  math.floor(texture:getWidth() * textureX) 
	for i = 1 + math.floor(viewerHeight - height)/2, -1 + math.floor(viewerHeight + height)/2 do
		local temph =  math.floor(texture:getHeight() * ((i-(viewerHeight - height)/2)) / height)
		local r,g,b,a = texture:getPixel(tempw,temph)
		if vHit then 
			love.graphics.setColor(r*.8,g*.8,b*.8, a)
		else
			love.graphics.setColor(r,g,b,a)
		end
		love.graphics.rectangle("fill", rayScreenPos,i,stripWidth, 2)
	end
end
Yeah, that little 13 is my framerate :(
Image
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Working Raycasting example! WolfenLöve 3D if you will...

Post by Jasoco »

You take each wall tile texture. Divide it into 1 quad for each pixel width. Draw the appropriate quad at the appropriate Y scale based on the strip's distance from the camera. Your problem is you're drawing every pixel instead of just each strip. My game will draw a minimum of 640 objects per frame. That's with a viewport of 640 pixels width equalling 640 rays.

You're thinking too far into it and in the old DOS ways. This is 2012. Quads are your friend!!! Your method will never get any faster since you're drawing thousands of pixels separately every frame. You have a sheet of wall tiles. You take each tile one at a time and (Say your wall is 64x64) make 64 different quads horizontally across each tile. So you end up with a quad sheet that can be called via something like this: wallQuad[tileNum][textureX]

In my game each texture is 64 pixels by 64 pixels. 64 is stored in a variable (That can be changed) called tileSize. This is used for everything. When a ray hits a wall, one of the variables that's returned (In Jfroco's original code) is "textureX". If you multiply textureX by the tileSize you end up with the quad location of the current tile. Draw that quad at that position with its scale for its height and you got yerself textured walls with better framerate.

Also, stripWidth is stupid and left over from slow computer days and I think it looks ugly so I destroyed it and got rid of every trace of it. My pixels are all 1:1. Not 2:1. The only reason it's in jfroco's code is because it was leftover from the Opera JavaScript code he ported which was leftover from the old DOS QBasic days when computers were slow as moles asses in winter.

Eventually my code will be available. But I don't know when. I'm too self-conscious about it and won't release it until it's perfect. Perfect. Absolutely perfect. Must be perfect. Must be clean.

My version also has floors and doors and soon ceilings and hopefully eventually a dynamic sky and pre-calculated lighting and better enemy and NPC AI and scripting and blood spatters and bullet holes on walls and the floor and the ability to place actual 3D polygonal objects in the game... Eventually. In time.

Right now with Löve 0.8.0 LuaJIT edition I get about the ballpark of 60FPS with everything going on. The final game will have a "low-res" mode that will make the draw resolution 320x200 (More faithful to Wolfenstein and DOOM) to help the speed if normal 640x400 mode is too slow. Right now walls and things will render at the 320x200 mode but the floor and sky render incorrectly. It's on my list of things to fix the hell out of.
Gravy
Citizen
Posts: 80
Joined: Sun Jan 22, 2012 10:15 pm
Location: CA, USA

Re: Working Raycasting example! WolfenLöve 3D if you will...

Post by Gravy »

Thanks! This was not too painful to implement, and I'm getting 60 FPS now.
LaserGuns
Prole
Posts: 33
Joined: Sun Apr 29, 2012 12:55 am

Re: Working Raycasting example! WolfenLöve 3D if you will...

Post by LaserGuns »

any more progress? or is there a new thread? i demand updates!
User avatar
legendman3
Citizen
Posts: 68
Joined: Sun Jan 22, 2012 8:29 pm

Re: Working Raycasting example! WolfenLöve 3D if you will...

Post by legendman3 »

I hope it didn't die. I liked this.
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests