# rendering level data issues?

This topic is 5423 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Usually some one would figure this out for them self, but I’m having difficulties with it. My problem is this. I have a 16x16 array of bytes. Each byte is either 1 or 0. A 1 stands for wall and a 0 stands for floor. I need to loop through the array and draw a wall for every 1 in the array. I am currently looping through the array drawing the wire frame mesh witch lays flat on the z plane. I need to make the walls, how do I do this? Is there a clever little algorithm for looping through a 2D array and making 3D walls from it? Each 1 in the array means draw a wall here. Do I just draw a 4 sided square for every 1 or is their a better way so I’m not rendering polygons that can’t bee seen?

##### Share on other sites
Oh yeah, I though of this for a solution.

1. Get camera view angle (rotation angel on yaw)
2. Find if wall facing camera
3. If wall is facing camera, draw quad representing wall.
4. Else, go to next wall in level
5. jump back to step 2

Now, the problem is finding if the wall is facing the camera or not and if it is blocked. Say if I have an array

0, 0, 0, 0,
0, 1, 0, 0,
0, 1, 0, 0,
0, 0, 0, 0,

and the camera is as 2,0, then how do I figure if the wall at 1,3 is facing the camera? Because it has two sides. The level data does not support normals so I can use them. The level data is arranged just like a tile map. Except the tiles stand for wall instead.

##### Share on other sites
I think I may have an answer. If I check each adjacent element to the current element I’m analyzing I can use that information on how to rend the wall.

Example:
0, 0, 0, 0
0, 1, 1, 0
0, 1, 1, 0
0, 0, 0, 0

On this array, element (1,1) is a wall. I wouldn’t make any cense drawing an entire cube. So I check each adjacent element to find if a wall exists there or not. I one does, then I do not draw a wall facing that side.

Element (1,0) = 0, so I draw a wall facing north. Element (0,1) = 0, so I draw a wall facing west. Elements (2,1) and (1,2) = 1, so I don’t draw any faces. Using this information, I can also create a simple normal that points in the direction the wall is facing perfectly. So I can cull out walls that the camera can’t see using that normal.

Now I need to make some sort of ray casting algorithm that finds which walls to draw. I think that will help speed up things a lot.

• 13
• 18
• 29
• 11