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

Direct3D 9 and 360 degrees

32 posts in this topic

I can move properly (or at least when I could see the object I could). I'll look up the code for printing text on the screen and then edit this post.
------------------

Nevermind. Bacterius, your formula was wrong. The right formula is:
[CODE]
LookX = cos(AngleX) * sin(AngleY);
LookY = sin(AngleX) * cos (AngleY);
LookZ = sin(AngleX) * sin(AngleY);
[/CODE]

Now a problem, how the heck do I make the camera look at the object?
It looks somewhere else to the point that I have to search for it, even though the camera and object are both at 0,0.

So the object is at 0,0,15
The camera at 0,0,0
and looks at whatever the sin and cos gives me.
If I multiply LookZ with 15.0f, I can make it look at it, but then the camera doesn't move properly for obvious reasons.

What do I do now?
0

Share this post


Link to post
Share on other sites
[quote name='theo2005' timestamp='1334999516' post='4933477']
Nevermind. Bacterius, your formula was wrong. The right formula is:
[CODE]LookX = cos(AngleX) * sin(AngleY);
LookY = sin(AngleX) * cos (AngleY);
LookZ = sin(AngleX) * sin(AngleY);[/CODE]
[/quote]
You must be mistaken. [url="http://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates"]http://en.wikipedia....ian_coordinates[/url].

If the object you want to look at is at the same position as the camera, then the camera's direction is undefined. It's like trying to look at your own eye: you can't do it. It doesn't make sense.

Now the explanation:

The idea is that the D3D lookat matrix function takes a *camera position* (which is the position of your camera as MoveX, MoveY, MoveZ), a *camera target* (which is MoveX + LookX, MoveY + LookY, MoveZ + LookZ) where LookX, LookY and LookZ is the direction vector you are looking at (obtained by the cos/sin formulas), and an *up vector* (which is (0, 1, 0) for your purposes). It doesn't get any more complicated.

You don't multiply LookZ by MoveZ or anything : you add them. The idea is that LookX, LookY and LookZ is a direction vector which describes the direction in which you are looking. It tells [b]nothing[/b] about position. It's a vector. So to obtain the actual *point* in 3D where the camera is looking at, you must add the direction vector to the camera's position.

Imagine: you are looking straight ahead of you at a ball 1 metre ahead, in the X direction. The direction vector (LookX, LookY, LookZ) is going to be (1, 0, 0). This information tells you [u]nothing[/u] about where you or the ball actually are. On the other hand if you know that you are standing at say, (3, 4, 5), then the ball must be at (3 + 1, 4 + 0, 5 + 0) = (4, 4, 5). You simply add the direction vector to the camera's position to obtain the camera's target.

[quote]

So the object is at 0,0,15
The camera at 0,0,0
and looks at whatever the sin and cos gives me.
[/quote]
This is where your logic is failing. The camera doesn't look [u]at[/u] whatever the sin and cos gives you. It looks [u]in the direction[/u] whatever the sin and cos gives you. To actually get the camera target for the D3D lookat function you need to add that direction to your camera's position to get another position corresponding to the target.

The object's position doesn't even come into play at all, at any time in the camera setup.

I hope it makes sense. When I come back from uni in a couple hours I will draw you a diagram to help you picture it if you are still confused.
0

Share this post


Link to post
Share on other sites
As promised here is the diagram (click to enlarge):


[img]http://i39.tinypic.com/10pd5rs.png[/img]

This is for the 2D case (in 3D the concept is exactly the same, except the vectors have three components and you need two angles to describe an arbitrary direction vector instead of one - this is where spherical coordinates come in). I hope this makes it a bit clearer to you.

So basically you use your two angles (controlled by the mouse) to change the direction in which the camera is looking (and you obtain the "look" direction vector by using spherical coordinates from the two angles and an arbitrary radius*), you use the keyboard to change the camera's position as usual, and you derive the camera's target by adding these two vectors together as the diagram shows. You then give this to the D3D LookAt function which will give you the view matrix you want.

* the radius does not matter in this case because as I explained earlier, using a bigger or smaller radius wouldn't change the direction of the "look" direction vector, which means the resulting matrix will be identical (because the function normalizes the "look" direction directly, which cancels out any scaling).
0

Share this post


Link to post
Share on other sites
Thank you for the thorough explanation!
I think I actually understand now.

You explained the theory and helped me get over
my misunderstandings, but my question is still unanswered [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

I am always at the mercy of what sin and cos gives me.
Sin and cos defines the point (excuse me, direction) where I look at when my program starts, I don't like that.
I want to set my starting view direction MYSELF.

It's not cool when you start a 3D rpg and instead of starting by
looking at the landscape, you look at the dirt below your feet.

Also, how am I supposed to make a camera follow a character and keep looking
at the direction of the character if I cannot define where I look at except for manually
following him with my mouse?

Oh and... my formula is right.
With your formula, the camera's view doesn't even shift on the Y axis and does some weird stuff.
With the formula I defined earlier, everything works perfectly.

I dont know why that is, but I wouldn't lie.

Cheers,
Theo
0

Share this post


Link to post
Share on other sites
[quote]I am always at the mercy of what sin and cos gives me.
Sin and cos defines the point (excuse me, direction) where I look at when my program starts, I don't like that.
I want to set my starting view direction MYSELF.[/quote]
You should be able to set the initial view direction by setting the initial values for the angles. You can use the inverse of the spherical coordinates to obtain angles from an actual direction (which can be more convenient, say you want to look ahead of you in the Z direction when you first start your program, you use the inverse spherical coordinates on the (0, 0, 1) vector, and obtain the correct two angles).


[quote]Also, how am I supposed to make a camera follow a character and keep looking
at the direction of the character if I cannot define where I look at except for manually
following him with my mouse?[/quote]
You still seem to be stuck on this. What I'm showing you is for first-person perspective (I thought this is what you wanted). It's obviously a lot different for third-person perspective, because then it depends on how what perspective you actually want (in terms of what happens when you move the mouse, what when you zoom in/out, etc...). As for the mouse, this is just the interface between you (the player) and your ability to change the view angles (which allow you to change in which direction the camera is looking).

[quote]Oh and... my formula is right.
With your formula, the camera's view doesn't even shift on the Y axis and does some weird stuff.
With the formula I defined earlier, everything works perfectly.[/quote]
I actually did make a mistake in the formula, it should be (this explains why it didn't work on the Y-axis):

LookX = cos(AngleX) * sin(AngleY);
LookY = cos(AngleY);
LookZ = sin(AngleX) * sin(AngleY);

My mistake - but it still doesn't make your formula correct. Your formula does not work. It only *appears* to work at first but as you said, when you make it do some stuff it eventually breaks down. If you implement spherical coordinates properly they will work in every single case (I have done it in my own camera code, as well as hundreds of other people, so they obviously work otherwise people wouldn't be using them and I wouldn't be explaining them to you).

I am not sure what you are looking for anymore. What is your goal? I was under the impression you wanted to implement a first-person perspective camera, where you use the keyboard to move the camera around the world and the mouse to look around (much as you would in any 3D first-person game). Please correct me if I was wrong because this is what I'm working under.
0

Share this post


Link to post
Share on other sites
[quote name='Bacterius' timestamp='1335170460' post='4934008']
say you want to look ahead of you in the Z direction when you first start your program, you use the inverse spherical coordinates on the (0, 0, 1) vector, and obtain the correct two angles).
[/quote]

How would I go about doing this in my program? And which vector are you referring at exactly?

[quote name='Bacterius' timestamp='1335170460' post='4934008']
LookX = cos(AngleX) * sin(AngleY);
LookY = cos(AngleY);
LookZ = sin(AngleX) * sin(AngleY);
[/quote]

Yup, this seems to work as well.

[quote name='Bacterius' timestamp='1335170460' post='4934008']
I am not sure what you are looking for anymore. What is your goal? I was under the impression you wanted to implement a first-person perspective camera, where you use the keyboard to move the camera around the world and the mouse to look around (much as you would in any 3D first-person game). Please correct me if I was wrong because this is what I'm working under.
[/quote]

My goal is to have a camera to look around in the world freely. But even so,
I'd love to have the camera pointing in the direction << I >> personally choose.
-----------------

The reason I also want to have the ability to choose where I look at, is because
then I can later use it to convert to 3rd person camera. My idea of it was to
make the camera follow the player from a certain distance and stay looking at
the character just by supplying the character movement values to the view vector.
But due to the fact that MY common logic does not work here, I deduce that just
putting the character movement values into the view vector will be of no good, thus
I still need to work with the formula you supplied me.

The problem is, the only way
I currently know how to make it point where I want, is multiplying one formula
for the chosen axis with the float number where I want it to point. That of course
breaks the camera view movement and yields incorrect results.

So the conclusion is that I was happy when the camera view movement finally worked, but at
the same time confused and disappointed that I have no means to choose the direction.
I thought that it might be okay if it's only to look around the world, but then I realized that
I wont be able to make a 3rd person camera.

--------------

The reason I might have confused you is because I never thought, nor still think of my current camera as a 1st person camera.
I think of it as spectator mode, or just a camera to look around the world. It highly upsets me that not only I cannot set where I look at
initially, but when I change the initial camera location (move values), even my camera view movement will become inverted on one axis.
(Let alone that for some reason increasing the value on Y axis will make the camera go up, but increasing the value on X axis will make the camera move LEFT not right.)
So.. I'm lost in a mystery.
0

Share this post


Link to post
Share on other sites
You can get a view direction from some angles, and you can invert this process to get the appropriate angles for a view direction... or just set an initial direction that you like the look of?
0

Share this post


Link to post
Share on other sites
[quote name='return0' timestamp='1335222674' post='4934273']
You can get a view direction from some angles, and you can invert this process to get the appropriate angles for a view direction... or just set an initial direction that you like the look of?
[/quote]

"Some angles"?
Please do show me how to set the initial direction in my code.
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