• 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

Calculating points behind camera

1 post in this topic

Hello guys.


I've been getting into crafting my own 3D-engine in Java (mostly for kicks, but also I like to have full control over everything I use).

It's been going great for the most part (haven't gotten far), and I can now draw wireframes almost perfectly.


The formula I use for calculating where to draw a point on the screen is:


zDifference = abs(z - camera.z);

screenX = camera.lens * (x - camera.x) / zDifference);
screenY = camera.lens * (y - camera.y) / zDifference);


This works just fine, except for one thing.

When the point goes back behind the camera, it completely stops working.


Ok, so obviously I shouldn't draw a point behind the camera, right? Problem solved? Well, almost...


Image a line, drawn between two points. Imagine walking past the first one, but the second one still being visible. When this happens, the line goes haywire, since the calculations for the first point stop working. So I can't just "not draw the point", since I need it to draw the complete line. I still need to calculate where on the screen (it will be off-screen, but still) this point should be drawn, so I can after that draw a line between the two.


You can check out and see the issue in-action here.


So, how should I go about fixing this? Is the formula completely stupid, or should I find a way to work around this issue?


Any response is greatly appreciated smile.png

Have a good one,


Edited by Vrokulaf

Share this post

Link to post
Share on other sites

You can see how other APIs, such as OpenGL and Direct3D, handles this. What they do is basically inserting a clipping stage in the middle of transforming the object from model space to screen space to clip the object so that nothing extends outside the view volume (basically represented by the borders of your window and the near and far clip planes of your camera).


Instead of transforming your coordinates all the way to screen coordinates in one go, transform the coordinates to an intermediate clip space coordinate. This coordinate system is typically bounded by a unit cube or something similar, and you can then clip your line or polygon against this unit cube to ensure that only the visible parts remain. Then, take the final step to transform the clipped objects into screen space and rasterize it.


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