RayCasting wrong floor/ceiling texture mapping

Started by
2 comments, last by vinterberg 5 years, 10 months ago

Hi people.

The problem is that the floor moves with the player in same time. But if not draw walls i can see, that floor is just rotating but not moving in any direction — it is static. In the correct implementation, the player must walk on the floor. I attach the animation on which this effect is visible and my code that implements the collision with the floor. I have tried different versions of code for floorcasting (from forums, sources, including current version — from lodev).

Note: I implemented level geometry as sectors (set of lines), not as blocks like in Wolf3d. I know that Doom uses bsp tree, and renders floor in different way. But I suppose that current way works with sectors too (but slowly).

 


               stripPosY = (ProjectionPlane.me().sizeInWorld.Y / 2 - (int)(stripHeight / 2));
               stripPosY += (int)stripHeight-1;
               startPixel = stripPosY;

               while (startPixel != ProjectionPlane.me().sizeInWorld.Y)
                {
                    float curdist = ProjectionPlane.me().sizeInWorld.Y / (2.0f * startPixel - ProjectionPlane.me().sizeInWorld.Y);

                    float weight = curdist / (float)(minimalDist);

                    float floorX = weight * ((PointF)minimalIntersection).X + (1.0f - weight) * (Player.me().worldPosition.X);
                    float floorY = weight * ((PointF)minimalIntersection).Y + (1.0f - weight) * (Player.me().worldPosition.Y);

                    int textureX = (int)(floorX * ProjectionPlane.imageFloor1.Width) % ProjectionPlane.imageFloor1.Width;
                    int textureY = (int)(floorY * ProjectionPlane.imageFloor1.Height) % ProjectionPlane.imageFloor1.Height;

                    textureX = (int)Math.Abs(textureX);
                    textureY = (int)Math.Abs(textureY);

                    SolidBrush b = new SolidBrush(ProjectionPlane.imageFloor1.GetPixel(textureX, textureY));

                    g.FillRectangle(b, stripX, startPixel, 1, 1);

                    startPixel++;
                }  

 

RpT7I.gif

Advertisement

So... looking at the initial calculation for floorX/floorY... why is the player's position involved a calculation that tries to determine the color of the floor at a given world-space X/Y position?

 

Also, if this is Java or Processing code? Every cast costs a full-depth type check, equivalent to, for a typical depth-5-heirarchy type with a couple Interfaces thrown in, usually about 50-200 comparisons and 10-25 function calls per cast. Eliminate the casting of minimalIntersection to a PointF by passing it in as the correct type, or at least move the cast out of the loop.

 

 

 

I'm just gonna leave your egregious use of singletons where they are. If you don't already know that's terrible code, this forum post is not gonna be enough space to explain otherwise.

RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
On 6/22/2018 at 6:12 PM, Alex0451 said:

SolidBrush b = new SolidBrush(ProjectionPlane.imageFloor1.GetPixel(textureX, textureY));

You're not deleting these brushes, so isn't that a huge memory leak?
Probably also not the fastest way to go about it.. How about writing pixels to a buffer, and then blit it to the screen when it's done?

Also, you need to take into account the player position, how else is the floor going to move with the player? :D

 

.:vinterberg:.

This topic is closed to new replies.

Advertisement