• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
chucara

Finding a projection matrix from a 2D image

4 posts in this topic

Hi,

I have been stuck on this problem for quite some time.. I think it is best described with a picture:

[img]http://www.chucara.dk/example.png[/img]
Imagine that this picture is taken of a table. I am able to find the four red dots and their coordinates on the pictures. Same goes for the green dot.

Now, I want to be able to find the location of the green dot in 2D space on the table. Assuming the following mappings:
(171,22) -> (0,0)
(488,155) -> (1,0)
(24,126) -> (0,1)
(361, 346) -> (1,1)

How do I determine what coordinate (167,128) maps to on the plane created by the table?

I seem to have read that I need to find a projection matrix (which I have a basic understanding of what is), but how?

Any hints or suggestions you can give me is very welcome, example calculations even more so.

Also, please point out if I am reinventing the wheel here. I am not aware of any libraries that do this already. (for .NET)
0

Share this post


Link to post
Share on other sites
I believe you can solve this problem using bilinear interpolation. To start with you have the formula,

x(s,t) = a_1 * s * t + a_2 * s * (1 - t) + a_3 * (1 - s) * t + a_4 * (1 - s) * (1 - t)

where 0 <= s <= 1, 0 <= t <= 1, and the a_i are 2D coefficients that we need to figure out. I'm going to define the boundary conditions you've provided as

A = (171,22)
B = (488,155)
C = (24,126)
D = (361, 346)

So now we use the boundary conditions to get

x(0,0) = a_4 = A
x(1,0) = a_2 = B
x(0,1) = a_3 = C
x(1,1) = a_1 = D

Or,

x(s,t) = D * s * t + B * s * (1 - t) + C * (1 - s) * t + A * (1 - s) * (1 - t)

This gives us a mapping from [0,1]x[0,1] to the co-ordinates specified by A, B, C, and D, but we actually need to the reverse so we need to invert this equation. First, the equation is actually made up of two equations: one for x component and one for y. We can write this as

P.x = D.x * s * t + B.x * s * (1 - t) + C.x * (1 - s) * t + A.x * (1 - s) * (1 - t)
P.y = D.y * s * t + B.y * s * (1 - t) + C.y * (1 - s) * t + A.y * (1 - s) * (1 - t)

where P is the point that we are trying to map to the [0,1]x[0,1] domain. To do this we isolate the 's' and 't' variables,

P.x = s * (D.x * t + B.x * (1 - t) - C.x - A.x * (1 - t)) + (C.x + A.x * (1 - t))
s = P.x - (C.x + A.x * (1 - t)) / (D.x * t + B.x * (1 - t) - C.x - A.x * (1 - t))

Similarly, for the y equation

s = P.y - (C.y + A.y * (1 - t)) / (D.y * t + B.y * (1 - t) - C.y - A.y * (1 - t))

Equating the equations for 's' we get.

(D.y * t + B.y * (1 - t) - C.y - A.y * (1 - t)) * (D.x * t + B.x * (1 - t) - C.x - A.x * (1 - t)) = (P.x - (C.x + A.x * (1 - t))) * (P.y - (C.y + A.y * (1 - t)))

As messy as this all looks it is just a quadratic equation. Solve for 't' and then plug it back into one of the equations for 's'.

-Josh
0

Share this post


Link to post
Share on other sites
Josh,

I can't yet claim to understand what you wrote, but I will have a look when I'm near some paper (I think I will need it). If this works, you are truely a mathemagician

Thanks a lot, I'll be sure to let you know if I can get it running.
0

Share this post


Link to post
Share on other sites
[quote name='chucara' timestamp='1326303312' post='4901694']
Josh,

I can't yet claim to understand what you wrote, but I will have a look when I'm near some paper (I think I will need it). If this works, you are truely a mathemagician

Thanks a lot, I'll be sure to let you know if I can get it running.
[/quote]

Well, make sure you check my working because I am very bad at making silly errors along the way.

Hope it works :-)

-Josh
0

Share this post


Link to post
Share on other sites
I have taken a look at it, and it does indeed seem like a correct way of doing this. However, I'm having a little trouble isolating t in the final equation without substituting the values for the ones that are known.

This means that I can at least verify that this is a correct solution by hand, but I can't implement it in code just yet.

Once again thanks. I will verify the solution tomorrow as it is getting late.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0