[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Pixel Location in 3D Space?
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Pixel Location in 3D Space?
- From: "Mike C. Fletcher" <mcfletch@xxxxxxxxxx>
- Date: Tue, 20 Dec 2005 21:32:31 -0500
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Tue, 20 Dec 2005 21:32:00 -0500
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=rogers.com; h=Received:Message-ID:Date:From:Reply-To:User-Agent:X-Accept-Language:MIME-Version:To:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=ojXPLwK4yDHhWSazOz78PVPvvbTUENNTWtQHe/4/6Ckw4/9PW6Yd03UtssXBYsl2uxTUOr9UA0tdgJjQkJJneZQag4vx4tOPxdpHYRd0gMaI8mXqxdCKdymMN/ncsRvG0aMXZrE8Iewj5yIdD+Rzpooe0u0be+UdSRp+Xjyevho= ;
- In-reply-to: <43A8B13D.8090706@comcast.net>
- References: <43A8B13D.8090706@comcast.net>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
- User-agent: Mozilla Thunderbird StumbleUpon/1.994 (X11/20051017)
HandyGM wrote:
Imagine taking a balloon in the shape of the 3D object, 'painting' the
texture map on it, then popping the balloon, leaving the paint hanging
where it was in 3D space when the model existed. For each 'dot of paint'
(pixel in the texture map), I want to know where it is in 3D space.
Basically, I want to map all the points in a texture map, to their
corresponding points in 3D space, given a standard 3D object of
arbitrary-sized polygons. Most of the time, the model is composed of
triangles and quadrangles, but sometimes there are polygons with more
sides.
Does anyone have an idea on how this might be accomplished?
* textures are mapped linearly across a triangle
o All polygons can be reduced to triangles during tessellation
o The corner of each triangle has a texture coordinate, again,
often generated during tessellation
o For any point on the surface of the triangle, the pixel
displayed is a linear blending of the texture coordinates of
the 3 points of the triangle, you'll find an equation in the
OpenGL spec for how that math works
* textures are applied (normally) to large numbers of triangles, and
can be repeated even within a single triangle (texture coordinates
with differences > 1), so for each pixel in the texture you have
up to NUMTRIANGLES 3D points for that pixel
o So, for each pixel
+ for each tessellated triangle
# for imagewidth in texture coordinate triangle width:
* for imageheight in texture coordinate
triangle height:
o test if
imagewidth+pixel,imageheight+pixel
is within coordinate triangle
+ if it is:
# take a linear blend of
the 3D points of the
triangle with the
weights for the texture
coordinates
However, that's a fairly generalised approach, if you've got X standard
objects and you just want to work with those you can likely simplify
some assumptions considerably. I've also not spent much time on how to
optimise it, there's likely a better way to do the "does this pixel in
any repetition show up within the triangle" test.
HTH,
Mike
--
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com