English 中文(简体)
Matrix to Represent a Triangle in Screen Space
原标题:

So i have a set of four points in 3D Space.

P1 [0, 0, 0]
P2 [128, 0, 0]
P3 [0, 128, 0]
P4 [128, 128, 0]

Which I m then projecting orthographically to the screen effectively giving me two wireframe triangles in screen space.

I now want to map a texture to this "plane" comprised of the two triangles. So i take my square texture, and using u,v coordinates I can map the texture into these two triangles.

The problem comes when I try to add a z component to the verticies. The resulting triangles in screen space are now somewhat distorted but the texture mapping is completely off.

It seems to me though that since it s just three points, they still form an affine rectangle of some sort and we can represent that rectangle as a matrix in the form:

[a b 0] [c d 0] [tx ty 1]

Can anyone give me some tips, ideas about how to convert three 2D points in screen space into a matrix in the above form?

All the tutorials etc that I ve looked up explain a loose theory of texture mapping, and then let OpenGl/DirectX native functions do the actual mapping.

I m looking for more of a direct approach where given three points, i can map a texure to that triangle using an affine matrix. (Not doing a scanline rendering approach)

Thanks!

最佳回答

I m not sure I understand what exactly you re looking for, but here s a way to transform from the (u,v) coordinates, to the screen coordinates.

Lets say you projected P1, P2, P3 to screen coordinates, and got 3 points with screen coordinates (x1,y1), (x2,y2) and (x3,y3).

Now we need a transformation from the form

[a, b, c] [d, e, f] [0, 0, 1]*[u, v, 1] = [x, y, 1]

and we want it to transform (0,0) to (x1,y1); (1,0) to (x2,y2) and (0,1) to (x3,y3). (this is because you want it to map your texture triangle to the projected triangle).

so we write all the equations:

0 a + 0 b + 1 c = x1
0 d + 0 e + 1 f = y1
1 a + 0 b + 1 c = x2
1 d + 0 e + 1 c = y2
0 a + 1 b + 1 c = x3
0 d + 1 e + 1 f = y3

and we solve them, and get:

a = x2-x1
b = x3-x1
c = x1
d = y2-y1
e = y3-y1
f = y1
问题回答

暂无回答




相关问题
Matrix to Represent a Triangle in Screen Space

So i have a set of four points in 3D Space. P1 [0, 0, 0] P2 [128, 0, 0] P3 [0, 128, 0] P4 [128, 128, 0] Which I m then projecting orthographically to the screen effectively giving me two ...

Using LINQ To SQL with multiple database tables

I have an employee class with as follows: public class Employee { public string FirstName { get; set; } public string LastName { get; set; } public string UserName { get; set; } ...

Mapping points from Euclician 2-space onto a Poincare disc

For some reason it seems that everyone writing webpages about Poincare discs is only concerned with how to represent lines and measure distances. I d like to morph a collection of 2D points (as ...

Fluent NHibernate, varbinary(max) and SQLite

I have a varbinary field in my sql server database that needs to be varbinary(max). I create my database with NHibernate and I use Fluent Nhibernate for my mappings. I also use SQLite for my unit ...

Javascript redirect

I am working with javascript and here is what I am trying to do: 1. Send a get request which looks like "http://localhost:8080/myapp/verify.htm?verifyId=Agkvhs" My requests reaches my verify.jsp in ...

热门标签