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

  • SEARCH
  • Home
  • 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 948123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:11:31+00:00 2026-05-15T23:11:31+00:00

I’m writing my own software rasterizer in Java, and I ran into some trouble

  • 0

I’m writing my own software rasterizer in Java, and I ran into some trouble with it… take a look at a sample image, please:

Image

This sample just draw simple square grid on a plane. Everything works fine until I move camera close enough for some points to move behind it. After that, they’re no longer projected correctly, as you can see (vertical lines – points that should be behind camera are projected on top of the screen).

My transformation matrices and vectors are same ones DirectX is using (PerspectiveFovLH for projection, LookAtLH for camera).

I’m using following transformation method to project 3D point:

  1. 3D vector to be transformed is created.
  2. Vector is multiplied by ViewProjection matrix.
  3. After that, point is transformed to screen using following method:

    // 'vector' is input vector in projection space
    // projection to screen
    double vX = vector.x / vector.z;        
    double vY = vector.y / vector.z;
    
    //translate
    //surfaceW is width and surfaceH is height of the rendering window.
    vX = (( vX + 1.0f) / 2.0f) * surfaceW;
    vY = ((-vY + 1.0f) / 2.0f) * surfaceH;
    
    return new Vector3(vX, vY, vector.z);
    

As I said earlier, it works fine until point moves behind camera. The fact is, I can figure out when the point is behind camera (by testing it’s Z value after final transform), but since I’m drawing lines and other line based objects, I can’t just skip that point.

Then I tried setting my transformation pipeline according to The Direct3D Transformation Pipeline article on MSDN.

Unfortunately, I haven’t had any luck with that as well (same results), so any help would be highly appreciated, since I’m a bit stuck on this one.

Thank you.

Best Regards,
Alex

  • 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-15T23:11:32+00:00Added an answer on May 15, 2026 at 11:11 pm

    You need to intersect the line with the front clipping plane in 3d space and truncate the line so you only draw the line segment that’s visible:

                 |
                 |
                 |
    x------------+-----------o
                 |
                 |
                 |   * - camera
                 |
                 |
                 |
           clipping plane
    

    You’ve got a line xo where x in front of the clipping plane and o behind it. Intersect this line with the clipping plane to generate the point +. You know which of x and o is visible so draw the line from x to +.

    This way you’re not projecting points which are behind the camera.

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

Sidebar

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.