Skip to main content
GameDev.net gamedev.net
🔒 Locked

FPS Raycasting Wall Texturing in Java

Started by SkyAphid Nov 30, 2011 at 1:36 AM 0 replies 1.7k views
Original Post
SkyAphid
SkyAphid
I have the engine working, and right now, the walls are solid colors. How would I go about slicing 64x64 textures to render onto the walls?

This is the code for rendering walls, it should be all you need to get the gist of drawing one kind of texture on all walls:

g.fillRect(sliceColumn, wallTop, 5(SliceWidth), wallHeight);

I need help on splitting 64x64 images into strips that fit onto the strips of wall I render in raycasting. I just can't do this, because I don't know how to efficiently go about splitting the images. I need a command that can use doubles, but most of buffered image commands use ints. Rendering them virtually useless to my cause.

Basically, I need to make rectangles with images. The finished product will be essentially the same as above with image drawing instead. I'm bordering on a 2d array, but the actual image slicing is the hard part.
zacaj
zacaj
You're going to need to copy each pixel manually. First, you'll need a function. on that can get the color of any x, y coordinate in the image you want to display on the wall. Then you'll need to linearly interpolation across the areas that your solid wall covers on the screen pixel by pixel, horizontally and vertically.
Think of it like a proportion. For each vertical column of pixels, you've got the height on the screen, and the height of the image you're going to display (64x64)
ScreenY. ImageY
---------- = ---------
ScreenH. ImageH

ScreenH is the height of the current column of pixels you're drawing to the screen
ImageH is the height of the image you're scaling (64)
If you can get one column of your image displaying over every column of the wall, it shouldn't be too hard to get the x coordinate of for the image too

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.