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 6241451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:46:15+00:00 2026-05-24T11:46:15+00:00

I’m attempting ray casting an octree on the CPU (I know the GPU is

  • 0

I’m attempting ray casting an octree on the CPU (I know the GPU is better, but I’m unable to get that working at this time, I believe my octree texture is created incorrectly).

I understand what needs to be done, and so far I cast a ray for each pixel, and check if that ray intersects any nodes within the octree. If it does and the node is not a leaf node, I check if the ray intersects it’s child nodes. I keep doing this until a leaf node is hit. Once a leaf node is hit, I get the colour for that node.

My question is, what is the best way to draw this to the screen? Currently im storing the colours in an array and drawing them with glDrawPixels, but this does not produce correct results, with gaps in the renderings, as well as the projection been wrong (I am using glRasterPos3fv).

Edit: Here is some code so far, it needs cleaning up, sorry. I have omitted the octree ray casting code as I’m not sure it’s needed, but I will post if it’ll help 🙂

void Draw(Vector cameraPosition, Vector cameraLookAt)
{
// Calculate the right Vector
Vector rightVector = Cross(cameraLookAt, Vector(0, 1, 0));

// Set up the screen plane starting X & Y positions
float screenPlaneX, screenPlaneY;
screenPlaneX = cameraPosition.x() - ( ( WINDOWWIDTH / 2) * rightVector.x());
screenPlaneY = cameraPosition.y() + ( (float)WINDOWHEIGHT / 2);

float deltaX, deltaY;
deltaX = 1;
deltaY = 1;

int currentX, currentY, index = 0;
Vector origin, direction;

origin = cameraPosition;
vector<Vector4<int>> colours(WINDOWWIDTH * WINDOWHEIGHT);

currentY = screenPlaneY;

Vector4<int> colour;

for (int y = 0; y < WINDOWHEIGHT; y++)
{
    // Set the current pixel along x to be the left most pixel
    // on the image plane
    currentX = screenPlaneX;

    for (int x = 0; x < WINDOWWIDTH; x++)
    {
        // default colour is black
        colour = Vector4<int>(0, 0, 0, 0);

        // Cast the ray into the current pixel. Set the length of the ray to be 200
        direction = Vector(currentX, currentY, cameraPosition.z() + ( cameraLookAt.z() * 200 ) ) - origin;
        direction.normalize();

        // Cast the ray against the octree and store the resultant colour in the array
        colours[index] = RayCast(origin, direction, rootNode, colour);

        // Move to next pixel in the plane
        currentX += deltaX;
        // increase colour arry index postion
        index++;
    }

    // Move to next row in the image plane
    currentY -= deltaY;
}

// Set the colours for the array
SetFinalImage(colours);

// Load array to 0 0 0 to set the raster position to (0, 0, 0)
GLfloat *v = new GLfloat[3];
v[0] = 0.0f;
v[1] = 0.0f;
v[2] = 0.0f;

// Set the raster position and pass the array of colours to drawPixels
glRasterPos3fv(v);
glDrawPixels(WINDOWWIDTH, WINDOWHEIGHT, GL_RGBA, GL_FLOAT, finalImage);
}

void SetFinalImage(vector<Vector4<int>> colours)
{
    // The array is a 2D array, with the first dimension
    // set to the size of the window (WINDOW_WIDTH * WINDOW_HEIGHT)
    // Second dimension stores the rgba values for each pizel

    for (int i = 0; i < colours.size(); i++)
    {
        finalImage[i][0] = (float)colours[i].r;
        finalImage[i][1] = (float)colours[i].g;
        finalImage[i][2] = (float)colours[i].b;
        finalImage[i][3] = (float)colours[i].a;
    }
}
  • 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-24T11:46:16+00:00Added an answer on May 24, 2026 at 11:46 am

    Your pixel drawing code looks okay. But I’m not sure that your RayCasting routines are correct. When I wrote my raytracer, I had a bug that caused horizontal artifacts in on the screen, but it was related to rounding errors in the render code.

    I would try this…create a result set of vector<Vector4<int>> where the colors are all red. Now render that to the screen. If it looks correct, then the opengl routines are correct. Divide and conquer is always a good debugging method.

    Here’s a question though….why are you using Vector4 when later on you write the image as GL_FLOAT? I’m not seeing any int->float conversion here….

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

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
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
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.