• 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
Hyunkel

View and Projection Matrices for VR Window using Head Tracking

10 posts in this topic

To illustrate what I am trying to do:
[url="http://www.youtube.com/watch?v=Jd3-eiid-Uw#t=2m45s"]http://www.youtube.c...eiid-Uw#t=2m45s[/url] (2m45s)


[font="arial, sans-serif"][size="2"]Johnny Chung Lee (who uploaded this video) used the Wii mote for head tracking, I want to do the same thing with a Kinect & OpenNI.[/size][/font]
[font="arial, sans-serif"][size="2"]However, my problem isn't related to the kinect or head tracking...[/size][/font]
[font="arial, sans-serif"] [/font]
[font="arial, sans-serif"][size="2"]My problem is that I'm having a hard time to wrap my head around setting up correct View and Projection matrices to look into a tunnel as shown in the youtube video.[/size][/font]
[font="arial, sans-serif"][size="2"]Here's an example:[/size][/font]
[font="arial, sans-serif"][size="2"][img]http://i.imgur.com/1L6Ed.png[/img]
[/size][/font]
[font="arial, sans-serif"][size="2"][font="arial, verdana, tahoma, sans-serif"][size="3"]
[font="arial, sans-serif"][size="2"][size="2"]Right now I just want to get this step to work, so I'm using keyboard input to move my camera around.[/size][/size][/font]
[font="arial, sans-serif"][size="2"][size="2"]It doesn't make much sense to do any head tracking before I got this working.[/size][/size][/font][/size][/font][/size][/font]
[font="arial, sans-serif"][size="2"]My problem is figuring out the correct View & Projection matrices for an arbitrary camera position in front of the TV screen, so the camera actually looks "through the screen".[/size][/font]
[font="arial, sans-serif"][size="2"]Here is what I tried:[/size][/font]
[font="arial, sans-serif"] [/font]
[font="arial, sans-serif"][size="2"][code]//Position = Camera Position
View = Matrix.CreateLookAt(Position, new Vector3(Position.X, Position.Y, 0), Vector3.Up);

//Create a perspective off center
//The tunnel model is 16f wide and 9f high (My TV is 16:9, resolution is 1920x1080)
//near and far planes are 0.05f & 500f
float left = nearPlane * (-16f + Position.X) / Position.Z;
float right = nearPlane * (16f + Position.X) / Position.Z;
float bottom = nearPlane * (-9f - Position.Y) / Position.Z;
float top = nearPlane * (9f - Position.Y) / Position.Z;
Projection = Matrix.CreatePerspectiveOffCenter(left, right, bottom, top, nearPlane, farPlane);[/code][/size][/font]
[font="arial, sans-serif"] [/font]
[font="arial, sans-serif"][size="2"]Oddly enough this seems to work on the Y axis, but not on the X axis?[/size][/font]
[font="arial, sans-serif"][size="2"]If I move the camera up or down I get the wanted effect.[/size][/font]
[font="arial, sans-serif"][size="2"]However if I move it left or right it just scrolls past the edge of the tunnel [/size][/font][font="arial, sans-serif"][size="2"](the perspective does not change)[/size][/font][font="arial, sans-serif"][size="2"]. :/[/size][/font]
[font="arial, sans-serif"][size="2"]I think I'm missing something here, but I can't figure out what it is.[/size][/font]
[font="arial, sans-serif"] [/font]
[font="arial, sans-serif"][size="2"]Any ideas / suggestions what I could try?[/size][/font]
[font="arial, sans-serif"] [/font]
[font="arial, sans-serif"][size="2"]Cheers,[/size][/font]
[font="arial, sans-serif"][size="2"]Hyu[/size][/font]
[font="arial, sans-serif"] [/font]
[font="arial, sans-serif"] [/font]
0

Share this post


Link to post
Share on other sites
Can you post some screenshots of what you are seeing? It is hard to visualize what the problem is...
0

Share this post


Link to post
Share on other sites
This should visualize the problem more easily:

The center of the virtual tv screen is at 0, 0, 0 and it measures 16 by 9 units
The camera coordinate is displayed at the top left of each screenshot:

Centered Camera:
[img]http://i.imgur.com/rqNgk.png[/img]


Camera offset to bottom: (This is the correct effect, it properly changes the projection)
[img]http://i.imgur.com/kzcKh.png[/img]



Camera offset to left: (This behaves incorrectly. It does not seem to change the projection, so the camera no longer looks through the virtual screen)
[img]http://i.imgur.com/i7gf5.png[/img]


Cheers,
Hyu
0

Share this post


Link to post
Share on other sites
I actually figured it out...
The correct near view plane should be calculated using:


[code]
float left = nearPlane * (-16f - Position.X) / Position.Z;
float right = nearPlane * (16f - Position.X) / Position.Z;
float bottom = nearPlane * (-9f - Position.Y) / Position.Z;
float top = nearPlane * (9f - Position.Y) / Position.Z;[/code]


and not

[font="arial, sans-serif"][size="2"][color="#1C2837"]
[code]
float left = nearPlane * (-16f + Position.X) / Position.Z;
float right = nearPlane * (16f + Position.X) / Position.Z;
float bottom = nearPlane * (-9f - Position.Y) / Position.Z;
float top = nearPlane * (9f - Position.Y) / Position.Z;[/code][/color][/size][/font]
I got confused with the different coordinates.
0

Share this post


Link to post
Share on other sites
Hi Hyu,

I have been struggling with the issue of head tracking and the associated projection matrix for few days now. Your posting has really helped. I am using Microsoft's own Kinect SDK but, like you, am using the keyboard to simulate head movement until I can get the viewing correct.

Here are some basic facts about my box/room:-[list]
[*]I am using units of 1M as thats what Kinect reports
[*]My box/room is 0.38 * 0.3 as that is my screen size in Meters
[/list]
I am having difficulty deciding on a few things:-[list]
[*]Where to place the centre of the open-end of the box/room in the world. I have tried it at 0,0,0
[*]Assuming the above, where to place the camera - I have it at 0.34
[/list]
This is what I see when the game first loads:-
[img]https://public.sn2.livefilestore.com/y1p5l3MaPUGC8o1UmiM2dKlQ3t9-hgEH0Ht_pCgtjF_GF-HlUeFhZINbOdyOtef5mwX1eD-lL0aK_SMU-lruECm0A/InitialScreen.JPG?psid=1[/img]

As you can see it does not fill the screen. If I the move the camera to the right, the perspective seems to change correctly and the open face of the room stays put:-
[img]https://public.sn2.livefilestore.com/y1pS-xEDPIuCOe-ChZStYwOh95bmUHAkalq73CEsIjawkB73qI-sgA4gw8balzyNtVh422cl0Ehm6Gk1aNuagmDfQ/CameraXChange.JPG?psid=1[/img]

Moving the camera in Z merely alters the perceived depth of the room, it does not change its position:-
[img]https://public.sn2.livefilestore.com/y1pdOZSTT2A3srYETvEzj6OGaaqomr7qawGVAAyH6TfS-S_plkrSERI3NQJBJXVhx6hnlwecBdn_9BYZ9aPTjfb0A/CameraZChange.JPG?psid=1[/img]

If I move the model so that it fills more of the screen (eg. Z=0.08) then move the camera in any direction, the image perspective is ok but the open face of the room has moved to the left as it appears to be rotating the room around world (0,0,0):-
[img]https://public.sn2.livefilestore.com/y1ppQ91z5AdC6DsorKjD96w_E3qB3rye36B4mIo6V0B87ZX8tsqnRMONZDHpfBq3lDp7KHPNwZUcoQQKeAYB6LXUQ/ModelMovePlusCameraXChange.JPG?psid=1[/img]

Have you any idea where I am going wrong? It feels so close.[list]
[*]I would like to fill the screen with the open face of the room
[*]Once in position, I want camera movements to affect the perspective of the view but leave the open face in place
[*]I would expect Z movement of the camera would affect perspective but would not zoom the image. Does that make sense and how did you achieve it?
[*]Would your camera position directly correlate with the head position as reported by Kinect or would you be doing some manipulation to keep the distance from head to screen center constant (some kind of orbital camera movement)?
[/list]
Here is my draw code in case I have something wrong there:-

[CODE]
matView = Matrix.CreateLookAt(cameraPosition, new Vector3(cameraPosition.X, cameraPosition.Y, 0.0f), Vector3.Up);

// from http://www.gamedev.net/topic/597564-view-and-projection-matrices-for-vr-window-using-head-tracking/
//Create a perspective off center
//near and far planes are 0.05f & 500f
float nearPlane = 0.05f;
float farPlane = 500f;
float left = nearPlane * (-.38f - cameraPosition.X) / cameraPosition.Z;
float right = nearPlane * (.38f - cameraPosition.X) / cameraPosition.Z;
float bottom = nearPlane * (-.3f - cameraPosition.Y) / cameraPosition.Z;
float top = nearPlane * (.3f - cameraPosition.Y) / cameraPosition.Z;

matProjection = Matrix.CreatePerspectiveOffCenter(left, right, bottom, top, nearPlane, farPlane);

// Draw the model. A model can have multiple meshes, so loop.
foreach (ModelMesh mesh in myModel.Meshes)
{
// This is where the mesh orientation is set, as well as our camera and projection.
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(0.0f)
* Matrix.CreateTranslation(modelPosition);
effect.View = matView;
effect.Projection = matProjection;
}
// Draw the mesh, using the effects set above.
mesh.Draw();
}
[/CODE]

I would be very interested to see the results that you achieved or the source code. I will gladly share mine once I am done.

Regards,
Steve
0

Share this post


Link to post
Share on other sites
I've been working through the head tracking projection problem recently as well. One thing I noticed is that some of the online samples use DirectX's LookAtLH and PerspectiveOffCenterLH. These are left-handed versions of the common way to create a View and Projection matrix. When using XNA, however, there are not left-handed methods available. CreateLookAt and CreatePerspectiveOffCenter are right-handed versions of those methods. I'm not totally sure how to convert from one to another; it's possible that multiplying the z-coordinate by -1 might do the trick.
0

Share this post


Link to post
Share on other sites
Unfortunately I can't seem to find the code I've written back when I posted this.

However I seem to recall most of the problems you are having.


[quote]
[left]As you can see it does not fill the screen. If I the move the camera to the right, the perspective seems to change correctly and the open face of the room stays put:-[/left]
[/quote]

If you want the box to fill the screen you have to align the perspective matrix with the size of your model.
For my tunnel I used a model that was 16.0f by 9.0f (my tv is 16/9)
So in order for it to fill up the screen I have to do a few things:
[img]http://i.imgur.com/1L6Ed.png[/img]

- Make sure the model origin (0, 0, 0) of the "tunnel in VR world" model is at the center of tv screen
- Position the "tunnel in VR world" model at (0, 0, 0)
- Make sure the top, right, bottom, left, top planes match the size of the model.
If your model is .38f by 3f then your calculations should be correct.

[quote]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]Moving the camera in Z merely alters the perceived depth of the room, it does not change its position:-[/quote][/size][/font][/color][/left]

[left][font=helvetica, arial, verdana, tahoma, sans-serif][color=#282828][size=3]If your goal is to create some sort of VR window, then this behavior is correct.[/size][/color][/font][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]I know that it looks weird, especially if all you have on display is an empty box.[/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]If you add more objects to the scene, or control camera movement with the kinect,[/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]you will notice that the effect is actually correct.[/size][/font][/color][/left]

[left][font=helvetica, arial, verdana, tahoma, sans-serif][color=#282828][size=3][quote][/size][/color][/font][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]If I move the model so that it fills more of the screen (eg. Z=0.08) then move the camera in any direction, the image perspective is ok but the open face of the room has moved to the left as it appears to be rotating the room around world (0,0,0):-[/quote][/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]You should not move the model at all![/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]In order to get the wanted behavior you have to line up your perspective matrix with the size of your model.[/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]The model always stays at (0, 0, 0), the only thing that changes is your camera position.[/size][/font][/color][/left]


[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][quote][/size][/font][/color][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]Would your camera position directly correlate with the head position as reported by Kinect or would you be doing some manipulation to keep the distance from head to screen center constant (some kind of orbital camera movement)?[/quote][/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]Well, here's where things get tricky.[/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]The camera position does directly correlate with the head position, yes. (no orbital camera movement or anything like that)[/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]You will get decent results doing this, but you will notice that something is off.[/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]This is because the kinect camera cannot be positioned at the center of your screen.[/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]You either have to put it below or above it, which causes the coordinate systems to no longer match up.[/size][/font][/color][/left]

[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]You can fix this by applying an offset to the camera position, which will equal the distance between the position of the [/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]kinect camera and the center of your screen.[/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]However this is still not 100% correct (but very close!)[/size][/font][/color][/left]

[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]The last issue is that your kinect camera is most likely angled upwards or downwards.[/size][/font][/color][/left]
[left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3]To get perfect results you have to take that into account as well.[/size][/font][/color][/left]


Here's a video I took while I was working on it:
[url="http://www.youtube.com/watch?v=usHyhLrk0vQ"]http://www.youtube.com/watch?v=usHyhLrk0vQ[/url]

As you can see the effect is not entirely correct, but that is because I couldn't put the camera in front of my head.
When I did, the kinect would no longer track my head properly, so I had to put it in front of my chest.

If you can't seem to get it to work properly I can have a look at your vs project if you want me to.
1

Share this post


Link to post
Share on other sites
These are awesome points. Thank you for posting these. I am not the original poster but I'm trying to do a similar thing and your answers have been very helpful.
0

Share this post


Link to post
Share on other sites
Hi Hyu,

Success! I had already been working through most of the issues that you mentioned (eg. Kinect not being at screen centre). I actually place my Kinect across the room, at my rght hand side. That allows it to track me right up to the screen. I obviously had to swap around the x,y,z values and incorporate the various offsets but the end result was good.

Regarding my main issue of the model appearing approx half as big as it should, I originally got around this by scaling my model by a factor of 2. This seemed ok until I was into the fine-tuning stage. Then I noticed that I had to move me head twice as far in x or y in order to get a specific view on the screen. I noticed this when trying to look straight down the edge of the room - I should have had my head in line with the edge of the screen for this but had to have it half as far away again. This was clearly related to the scaling that I had done to the model.

After a lot of head scratching and scribbled calculations I was struggling until I looked at the following document very closely ([url="http://www.cs.ubc.ca/labs/imager/PROCAMS2011/0008.pdf"]http://www.cs.ubc.ca/labs/imager/PROCAMS2011/0008.pdf[/url]). In section 5.2 they present a formula for the projection matrix that is so similar to the one that you presented above. The key difference is that they were using a half of the screen/model width and a half of the screen/model height. When I modified your projection matrix I found that I no longer needed to scale my model by 2 and the viewing angles were now correct when trying to look down the edge of the room/screen.

So, using my screen of 0.38M wide by 0.3M high with a model of the same size, my projection matrix becomes:-
[CODE]
left = nearPlane * ((-.38f / 2) - cameraPosition.X) / cameraPosition.Z;
right = nearPlane * ((.38f / 2) - cameraPosition.X) / cameraPosition.Z;
bottom = nearPlane * ((-.3f / 2) - cameraPosition.Y) / cameraPosition.Z;
top = nearPlane * ((.3f /2 ) - cameraPosition.Y) / cameraPosition.Z;
[/CODE]

Thanks for all your help. All I need to do now is do some decent models with textures and my demo will be complete. I will try to remember to post a video when it is finished.

Steve
0

Share this post


Link to post
Share on other sites
Glad to hear you got it working!

Positioning the kinect to your side is a pretty cool idea when doing head tracking.
0

Share this post


Link to post
Share on other sites
Hi ,
i am having the same projection problems too , Problem is i am doing a aircraft simulator which needs three monitor set-up using projectors so i have to render my scene with three different projections to simulate the view of the airport but couldn't quite able to do and struggling with it since past 2 day's could you guys please help me out with this .
thank you . my problem and how i want my projections is explained in the picture below .


[sharedmedia=gallery:images:2493] Edited by rakeshkr590
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