POV-Ray : Newsgroups : povray.advanced-users : Pixel position from 3D coordinates : Pixel position from 3D coordinates Server Time
3 Jul 2024 04:50:13 EDT (-0400)
  Pixel position from 3D coordinates  
From: Slagheap
Date: 24 Sep 2008 01:05:00
Message: <web.48d9c9c6b4e5a4f9220734020@news.povray.org>
I'm using Povray to render graphical elements to be used in a computer game.
It's a board game, so I have a camera looking at a board (at a nice perspective
angle), and I have game pieces on the board.

For the game board, it's easy... I render the full image with no pieces.  Done.

To generate the game piece graphics, I generate full-board images with subsets
of pieces in situ on the board, but with the board set as no_image, and the
background pixels transparent.  I can then load several of these full images
into my game program, and manually select slices of them for a given piece.  I
can have several game pieces in each image (as long as they have a
non-overlapping rectangle bounding box.

I also considered generating individual bounded images for the pieces (rendered
at all the various positions).  This essentially amounts to crops of the images
in option 1.  That options seems to only complicate everything below...  so I
think the first option is better, but I'm open to suggestions.

******* The problem: *******

How do I know where (in output-image pixels) to make my image slices for each
game piece?

I.e. inside my game program, I load the full image with pieces rendered in
several places.  How can I find the (x, y, width, height) of a slice from the
rendered image to overlay the board so that I show that one game piece?

I could manually go in and figure out where all these slices need to be made,
but that's a huge pain, and if I decide I need to change my camera position or
something, I would have to do this again.  I want a programmatic solution.

******* A guess at a solution:  *******
(which I don't know how to do)

If I could find the output-image pixel position for a given 3D coordinate in my
scene, I could pretty easily mark locations in the scene and export a text file
that has the pixel coordinates.

Better yet would be to find the pixel position for the corners of a camera-view
bounding box for each piece.  That way I don't have to manually figure out
where those 3D dots should go to fully bound the object.

Is there a trick for doing this without writing a reverse ray-tracer in SDL?  So
far, my camera is simple, so maybe this is not that hard...

camera {
  location <44, 27.5, 0>
  look_at  <0.5,0,0>
  angle 39.5
  right <720/340, 0, 0>  // 720 x 340 output image
}

Thanks,
Malcolm


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.