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

Archived

This topic is now archived and is closed to further replies.

AndyMan

intersection line & surface, drawing terrain

6 posts in this topic

Suppose we have an area of land, with height of each grid point stored in an array. You can write a function which calculates height at any x,y by interpolating. When you choose a camera angle you can create a matrix which will convert x,y,h(x,y) into screen coordinates. But is there a simple way to convert back the other way? Suppose you want to iterate through the whole screen and calculate the x,y,z using the matrix and the height function, so you can choose a colour for the pixel (based on a tilemap of x,y or height or slope or whatever). You can assume a continuous surface, although there may be steep slopes. This is essentially a mathematical problem - find the (first) intersection between a line and a surface. Point me to another thread or article if necessary, I imagine a lot of people have had to work this out before me.
0

Share this post


Link to post
Share on other sites
You''re describing ray-tracing. Just type ''ray tracing'' into a search engine and you should get all the info you need.
0

Share this post


Link to post
Share on other sites
it''s very simple

to find and intersection point of a ray (line) and a plane you have to do this :

lets consider a ray : X=A+t*V
where X is any point on the ray , t is a scalar and V is the direction vector of the ray.

now , lets consider a plane : X dot N + D=0
where X is any point on the plane, N is the normal to the plane and D is a scalar unique to the plane

all we have to do is find a point Xi that fits both eqations :
Xi dot N+D=0 , but Xi=A+t*V , so :
(A+t*V) dot N +D=0
A dot N + t*V dot N +D =0
t=-(D+A dot N)/(V dot N )

back to the first equation , replace t and there you go , the intersection point !!!
0

Share this post


Link to post
Share on other sites
You gave a solution for a ray and a flat plane. I was talking about a surface described by a 2D array of height values.

I looked around for stuff about raytracing and most of it is about intersections of lines with geometric shapes, which gives you a mathematical solution. But looking at a height map is one which probably requires some iterative method to zoom in on the right point. Any ideas?
0

Share this post


Link to post
Share on other sites
You want to perform collision dection with a ray and the world, it''s called "picking".

You need a tree structure which you use to perform culling, so that you don''t have to test the ray against every polygon in the world - I think you can use a quadtree or bsp tree for terrain.

I wouldn''t know how to explain the math, it''s a little involved, not too hard but lots of vectors and a few matrices, which are hard to show in ascii...

Magmai Kai Holmlor
- Not For Rent
0

Share this post


Link to post
Share on other sites
What you''re calling ''picking'' in this case is going to end up being ray tracing against polygons generated from the height map.
When you ''picking'' for every pixel on the screen, you are ray tracing or at least ray casting.

You could do that, but it''ll be faster to draw all the triangles with frustrum culling and maybe LOD. Even in a pure software renderer.

It sounds to me that AndyMan is trying to find an intersection between a ray and the surface that is defined by function h(x,y).
You can do this - for some types of h(x,y)

Unfortunately, while the surface may be continuous, it''s derivative is probably not. This is because your function h(x,y) is really selecting from a whole bunch of different plane equations depending on which x and y you''ve got. I think if you want to solve this mathematically in any sane manner, you would need to generate a more complicated surface from your height map that uses one equation and not switching between several distinct equations. Some type of spline function, perhaps.
0

Share this post


Link to post
Share on other sites
Look into voxel rendering. Yu''ll get a better idea of how the kind of stuff you''re talking about can be done efficiently.

But, in pure 3d space with no restrictions, what you want to do is raytracing, pure and simple.

There is no heightmap-screen pixel equivalency that can be worked backwards from the screen pixel to the heightmap cell short of raytracing. Why? Well, for one thing, on the screen, some mountains are behind other mountains. You know that rule in math, that in a graph, if a vertical line can intersect more than 1 part of it at any location, it''s not a function? Well, you''re trying to essentially find a function that can be intersected by a vertical line. It can''t be done. Algorithmically, the only equivalency can be found through ray-tracing, and that''s rather brute-force. But, like I said, if you limit some freedom on the part of the player, you can start doing all kinds of cool things, and that''s called voxel rendering.

On a side note, I am positive that the key to efficient terrain rendering lies in the old voxel techniques - specifically wavesurfing. And if adapted, you can get more freedom.
0

Share this post


Link to post
Share on other sites