Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7076343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:17:13+00:00 2026-05-28T06:17:13+00:00

I’m creating a minecraft like voxel engine thing in xna, and have started about

  • 0

I’m creating a minecraft like voxel engine thing in xna, and have started about implementing “infinite” world but have ran into a few problems. One such problem is that the following line always seems to apply the oppisite (eg if the player moved X+ REGION_SIZE_X it would assign Direction.X_DECREASING instead of the expected Direction.X_INCREASING).

    Thread regionLoader;

    public void CheckPlayer()
    {
        Direction direction = Direction.MAX;

        float distancetraveledx = player.Origin.X - player.Position.X;
        float distancetraveledy = player.Origin.Y - player.Position.Y;
        float distancetraveledz = player.Origin.Z - player.Position.Z;

        if (distancetraveledx > Variables.REGION_SIZE_X)
        {
            direction = Direction.XIncreasing;
            player.Position = new Vector3(player.Origin.X, player.Position.Y, player.Position.Z);
        }
        else if (distancetraveledx < -Variables.REGION_SIZE_X)
        {
            direction = Direction.XDecreasing; 
            player.Position = new Vector3(player.Origin.X, player.Position.Y, player.Position.Z);
        }
        else if (distancetraveledz > Variables.REGION_SIZE_Z)
        {
            direction = Direction.ZIncreasing;
            player.Position = new Vector3(player.Position.X, player.Position.Y, player.Origin.Z);
        }
        else  if (distancetraveledz < -Variables.REGION_SIZE_Z)
        {
            direction = Direction.ZDecreasing;
            player.Position = new Vector3(player.Position.X, player.Position.Y, player.Origin.Z);
        }
        if (direction != Direction.MAX)
        {
            regionManager.direction = direction;

            regionLoader = new Thread(new ThreadStart(regionManager.ShiftRegions));
            regionLoader.Start();
        }
    }

So what this is doing is checking if the player has moved REGION_SIZE from it’s origin and if it has, reset the component of the position which has moved over that boundary.

This then calls the following function:

    public void ShiftRegions()
    {
        // Future and current arrays are to avoid moving elements twice (or maybe I am thinking about it in the wrong way...)
        future_regions = new Region[(int)Variables.RENDER_DISTANCE, (int)Variables.RENDER_DISTANCE, (int)Variables.RENDER_DISTANCE];

        for (short j = 0; j < future_regions.GetLength(0); j++)
        {
            for (short m = 0; m < future_regions.GetLength(1); m++)
            {
                for (short i = 0; i < future_regions.GetLength(2); i++)
                {
                    future_regions[j, m, i] = new Region(world, new Vector3i(new Vector3(j, m, i)));

                    switch (direction)
                    {
                            // This appears to work as XDecreasing
                        case Direction.XIncreasing:
                            // If it is not at the back
                            if (j != future_regions.GetLength(0) - 1)
                            {
                                // Make the regions look like they are scrolling backward
                                future_regions[j, m, i] = regions[j + 1, m, i];
                                future_regions[j, m, i].Index = new Vector3i((uint)j, (uint)m, (uint)i);
                                // In the next call the vertex buffer will be regenerated thus placing the "blocks" in the correct position
                                future_regions[j, m, i].Dirty = true;
                            }
                            // If it is the front most region to which the player is traveling ing
                            if (j == 0)
                            {
                                // New the region setting the Generated flags to false thus allowing it to be regenerated
                                future_regions[j, m, i] = new Region(world, new Vector3i(new Vector3(j, m, i)));
                            }
                            // If it is at the back of the regions
                            if (j == future_regions.GetLength(0) - 1)
                            {
                                //store region
                            }

                            break;
                        case Direction.XDecreasing:

                            break;
                    }
                }
            }
        }


        generator.build(ref future_regions);
        direction = Direction.MAX;

        this.regions = future_regions;
    }

This actually moves the regions which causes the scrolling effect and the new regions which appear at the front. Which doesn’t seem to work.

I was thinking istead of actually “moving” the regions i could just assign different offsets and move in the world matrix but when I do so i just get a blue screen…

Here is the rest of the code:

Generator class function:

    public virtual void build(ref Region[,,] regions)
    {


        for (short j = 0; j < regions.GetLength(0); j++)
        {
            for (short m = 0; m < regions.GetLength(1); m++)
            {
                for (short i = 0; i < regions.GetLength(2); i++)
                {
                    OutputBuffer.Add("Generating...");

                    if (regions[j, m, i].Generated == false)
                    {
                        regions[j, m, i].Dirty = true;
                        regions[j, m, i].Generated = true;

                        for (short x = 0; x < Variables.REGION_SIZE_X; x++)
                        {
                            for (short y = 0; y < Variables.REGION_SIZE_Y; y++)
                            {
                                for (short z = 0; z < Variables.REGION_SIZE_Z; z++)
                                {
                                    regions[j, m, i].Blocks[x, y, z] = new Block();

                                    Vector3i relativeBlock = new Vector3i(new Vector3(x + Variables.REGION_SIZE_X * j, y + Variables.REGION_SIZE_Y * m, z + Variables.REGION_SIZE_Z * i));

                                    if (x == 0 || x == 16 || x == 32 || z == 0 || z == 16 || z == 32 || y == 0 || y == 16 || y == 32)
                                    {
                                        regions[j, m, i].Blocks[x, y, z].BlockType = BlockType.dirt;
                                    }
                                    else
                                    {
                                        regions[j, m, i].Blocks[x, y, z].BlockType = BlockType.grass;

                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

and the code that checks if the region’s buffers need to be rebuilt:

    public void Update(World world)
    {
        this.world = world;

        for (short j = 0; j < regions.GetLength(0); j++)
        {
            for (short m = 0; m < regions.GetLength(1); m++)
            {
                for (short i = 0; i < regions.GetLength(2); i++)
                {
                    if (regions[j, m, i].Dirty &&
                        regions[j, m, i].Generated)
                    {
                        regions[j, m, i].BuildVertexBuffers();
                    }
                }
            }
        }
    }

By the way, if Dirty is set to true this means that the buffers need to be regenerated.

Any ideas why this is not creating new regions at the front and why it is not scrolling properly?

EDIT: I was just thinking logically and that my idea with the changing the regions position in the array will not change it’s world position, and like I said above with transforming them to the correct positions instead of copying them – that seems like the most logical step. Well the thing is I may have to copy some to different places in the regions array because the array may become spaghetti in no time if you just transform them…

Thanks, Darestium

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:17:13+00:00Added an answer on May 28, 2026 at 6:17 am

    Just looking at this part

    float distancetraveledx = player.Origin.X - player.Position.X;

    You’re subtracting position from origin, you should probably reverse the order and do this

    float distancetraveledx = player.Position.X - player.Origin.X;

    For example, if the player has moved from (0, 0, 0) to (10, 0, 0), the player has moved 10 units in the X direction, but your ‘distancetraveledx’ would give you 0 – 10, or -10.

    Unrelated to your question:
    Your variables will be easier to use if you follow CamelCase, with the first letter lower or upper-case:

    float distanceTraveledX = player.Position.X - player.Origin.X;

    In C# the convention is to have class names with the first letter capitalized, and variables with the first letter lower-case, like such:

    MyClass myClass;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.