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

Offsetting 3D Points Based On Rotation + Position Of Camera

8 posts in this topic

 Please keep in mind that I graduated High School in 1998, and I am very rusty on advanced math !

 

 I have set up a basic Object that contains all my point data ( X Y Z ) for my 3D cube. Whenever it renders in the world, it does not rotate with the "camera" . ( It does move on X Y )

 

What are the SIMPLIFIED math formulas that are required to offset the points based on the camera's movement and rotation ?

 What are the SIMPLIFIED math formulas required for scaling as the camera approaches and retreats  ?

0

Share this post


Link to post
Share on other sites
The formulas are what they are, and they can't be simplified, unless you happen to be restricting yourself to some particular case. I am afraid you are going to have to bite the bullet and learn about vectors and matrices and how they can be used to represent 3D movements and projection.
0

Share this post


Link to post
Share on other sites

The formulas are what they are, and they can't be simplified, unless you happen to be restricting yourself to some particular case. I am afraid you are going to have to bite the bullet and learn about vectors and matrices and how they can be used to represent 3D movements and projection.

I do apologize, but I have no clue how to do most of THIS TYPE of math any more ...

0

Share this post


Link to post
Share on other sites
I'll try to work with you, but I need a bit of information to get started: How do you currently describe your camera's position and attitude?
0

Share this post


Link to post
Share on other sites

In relation to space:

 

Global X Y Z

Object X Y Z S ( offsets to Global in theory )

Camera X Y Z S ( takes Global and offsets to camera perspective in theory )

 

Camera pitch in radians

Camera yaw in radians

 

S = scale or distance

* Objects have internal pitch and yaw - however they are not used

0

Share this post


Link to post
Share on other sites
I can give you some simple formulas to work with. We'll start with a very simple situation, where we measure everything in pixels and the camera is an eye at a fixed position (0, 0, -1000), looking towards the origin. Our resolution is 1024x768. We can just think of this situation as having the screen contained between (-512, -384, 0) and (+512, +384, 0). So a point (x, y, z) when z = 0 will map to the pixel (512+x,384-y).

If that's clear, we just need to know how to scale things that are farther away from or closer to the eye than the screen. The answer is that point (x,y,z) maps to pixel (512+x*1000/(z+1000), 384-y*1000/(z+1000)). You can convince yourself that this is correct by making a picture of the situation (I suggest from above, to get the formula for the x coordinate) and using triangle similarity.

Now you need to know how to handle other camera positions and angles. Let's handle yaw first. You can rotate the whole world around the origin on the XY plane by using these formulas:

x' = x * cos(angle) - y * sin(angle)
y' = x * sin(angle) + y * cos(angle)

Do that to every point in the scene and your whole world has now rotated around the origin. If you want the rotation to happen around any other point, first subtract the coordinates of the center of rotation, then rotate, then add them back. In particular, you can now perform rotations around the camera, which has the same effect as rotating the camera.

For pitch you can do the same thing in the YZ plane. The order of rotations does matter. You probably want to apply pitch first and then yaw, but if that doesn't do what you want, reverse the order.

Moving the camera around is pretty easy, since all you have to do is -again- move the whole world in the opposite direction, by subtracting some vector from every point.

That's the closest I can get to "simplified math". I hope it helps. But you should really really try to find a gentle introduction to the algebra of matrices and vectors and try to understand the formulas you've found in other places.
2

Share this post


Link to post
Share on other sites

I seem to be getting a lot of EOB errors and inconstant data - this worked fine before the math was introduced . sad.png

int xx = width/2 ;
	    int yy = height/2 ;
	   
	   for (int i = 0; i < 361; i++){
		  //img = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
		   pixle( (int)( xx * Math.cos(i) - yy * Math.sin(i) ) ,(int) ( xx * Math.sin(i) +  yy * Math.cos(i) ) );
		   frame.repaint();
		   sleep(5);
	   }
[snip]
public void pixle(int x,int y){
		 System.out.println("~" + c + "\n" + x + " " + y );
		 try{
		 img.setRGB(x, y, color.getRGB() );
		 img.setRGB(x + 1 , y, color.getRGB() );
		 img.setRGB(x -1 , y, color.getRGB() );
		 img.setRGB(x , y + 1, color.getRGB() );
		 img.setRGB(x, y - 1, color.getRGB() );
		 } catch(Exception e){System.out.println("Error - EOB");}
		 c+= 1 ;
	 }

 

// without the try block

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
    at sun.awt.image.IntegerInterleavedRaster.setDataElements(Unknown Source)
    at java.awt.image.BufferedImage.setRGB(Unknown Source)
    at me.RLS0812.Mic_Code.b.pixle(b.java:72)
    at me.RLS0812.Mic_Code.b.<init>(b.java:44)
    at me.RLS0812.Mic_Code.Main.main(Main.java:23)

 

// with try block

~1
341 192
~2
22 390
Error - EOB
~3
-316 230
Error - EOB
~4
-364 -141
Error - EOB
~5
-77 -383
Error - EOB
~6
280 -272
Error - EOB
~7
381 89
~8
130 368
~9
-239 309
Error - EOB
~10
-389 -34
Error - EOB
~11
-181 -346
Error - EOB
~12
193 -340
Error - EOB
~13
390 -20
Error - EOB
~14
228 317
~15
-143 364
Error - EOB
~16
-383 75
Error - EOB
~17
-271 -282
Error - EOB
~18
90 -380
Error - EOB
~19
369 -129
Error - EOB
~20
308 240
~21
-36 389
Error - EOB

[snip]

Edited by Shippou
-1

Share this post


Link to post
Share on other sites

Is this formula verbatim, or programmatically ?

The answer is that point (x,y,z) maps to pixel (512+x*1000/(z+1000), 384-y*1000/(z+1000)).

x = ( width / 2 + ( x * focus ) ) / ( z + focus )
y = ( width / 2 - ( y * focus ) ) / ( z + focus )
or
x = ( ( ( height / 2 ) + x ) * focus) / ( z + focus )
y = ( ( ( height / 2 ) - y ) * focus) / ( z + focus )


Neither:

x = width / 2 + x * D / (z + D)
y = height / 2 - y * D / (z + D)

But, really, you should try to figure out how this works on your own.


EDIT: I had to add a quote of the post I was responding to, because it was later edited, rendering the conversation absurd. Please don't do that! Edited by Álvaro
0

Share this post


Link to post
Share on other sites

I seem to be getting a lot of EOB errors and inconstant data - this worked fine before the math was introduced . sad.png


Two things:
(1) Don't edit a post in such a way that the conversation makes no sense.
(2) Do your own debugging.
1

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