• 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
Jesse Dager

Custom 3D graphics engine

7 posts in this topic

I am constructing a hand held game system out of an atmega328p chip. I have basic functions written for this chip to write to my portable screen such as drawline, drawrect, drawcirc, fillrect, fillcirc, drawpoint, etc. I am attempting to create a basic 3D engine for this system using lines to imitate 3D wireframe graphics. I know that to do this, I need to calculate where the line endpoints would be to give perspective, however, I do not know where to start with these algorithms. How would I write a function that would create a line in 3D virtual space and convert it to a 2D image?

Something like:

void drawline3(int x, int y, int z)
{
     //calculate line position
     drawline(x, y);   //draw the line as a 2D line
}

 

 

 

 

 

P.S. I am new to the forums, so if this is posted in the completely wrong place, I apologize.

 

0

Share this post


Link to post
Share on other sites
How would I write a function that would create a line in 3D virtual space and convert it to a 2D image?

 

That process is called projection, you need projection matrix, check the projection matrices in OpenGL and DirectX. this link might help you.

2

Share this post


Link to post
Share on other sites

When you have the basic understanding on what math/matrix operations you need, I would recommend to use the glm library. It supports most of the math you need for projections and other matrix operations.

2

Share this post


Link to post
Share on other sites
When you have the basic understanding on what math/matrix operations you need, I would recommend to use the glm library. It supports most of the math you need for projections and other matrix operations.

See, my problem with using the GLM library, is it is not available for an avr chip simply because there is not enough memory

0

Share this post


Link to post
Share on other sites
The first time I did any 3D graphics, I used a camera that sits at (0,0,-FOV) looking towards the origin. In that case, the projection is simply:

projected_x = x * FOV / (FOV + z)
projected_y = y * FOV / (FOV + z)

So things with z=0 are seen at "real size" (I was measuring everything in pixels), things that have z>0 are seen smaller, and things that have z<0 are seen larger.

Perhaps that would be an easy place to start for you.
2

Share this post


Link to post
Share on other sites
The first time I did any 3D graphics, I used a camera that sits at (0,0,-FOV) looking towards the origin. In that case, the projection is simply:

projected_x = x * FOV / (FOV + z)
projected_y = y * FOV / (FOV + z)

So things with z=0 are seen at "real size" (I was measuring everything in pixels), things that have z>0 are seen smaller, and things that have z<0 are seen larger.

Perhaps that would be an easy place to start for you.

This is a perfect place for me to start! thank you! I still am looking for help on the subject, but at least now I have a basis for what to start my coding on.

0

Share this post


Link to post
Share on other sites

I wrote a basic camera movement code that goes with the calculations you posted, Alvaro. It seems to work well other than the glitches encountered when the camera edges touch the lines. This can be fixed, however, easily. I am working on that now. 

I wrote code to draw lines and cubes based on the calcs. I use an LCD header file that handles all the line drawing.

 

Here is my 3D.h file:

int FOV = 80;
int camx;
int camy;
int camz;
int screensizex = 84;
int screensizey = 48;
int campos(int camx1, int camy1, int camz1){
	camx = camx1;
	camy = camy1;
	camz = camz1;
}
int projectedx(int x, int z, int fov){
	int pro_x;
	pro_x =  (x * fov / (fov + z) + (screensizex / 2));
	return(pro_x);
}

int projectedy(int y, int z, int fov){
	int pro_y;
	pro_y = y * FOV / (FOV + z);
	return(pro_y);
}

void drawline3(int x, int y, int z, int x1, int y1, int z1){
	LcdLine( projectedx(x, z, FOV), projectedx(x1, z1, FOV), projectedy(y, z, FOV), projectedy(y1, z1, FOV), PIXEL_ON);
}

void drawcube(int x, int y, int z, int x1, int y1, int z1){
	x = x + camx;
	y = y + camy;
	z = z + camz;
	x1 = x1 + camx;
	y1 = y1 +  camy;
	z1 = z1 + camz;
	//frontface
	if(z << camz){
	drawline3(x, y, z, x1, y, z);
	drawline3(x, y, z, x, y1, z);
	drawline3(x1, y, z, x1, y1, z);
	drawline3(x1, y1, z, x, y1, z);
		//connectors
	drawline3(x, y, z, x, y, z1);
	drawline3(x1, y, z, x1, y, z1);
	drawline3(x, y1, z, x, y1, z1);
	drawline3(x1, y1, z, x1, y1, z1);
	}
	if(z1 << camz){
	//backface
	drawline3(x, y, z1, x1, y, z1);
	drawline3(x, y, z1, x, y1, z1);
	drawline3(x1, y, z1, x1, y1, z1);
	drawline3(x1, y1, z1, x, y1, z1);
	}
}
0

Share this post


Link to post
Share on other sites

according to your first code you want "perspective", means you need a perspective transformation, which is not an affine transformation, so you have to use homogenous coordinates

you should setup a basic rendering pipeline to transform you vertices (lineendpoints) to screenspace

 

vertex position -> view transformation (if you want a moving camera) -> perspective transformation -> homogenize your coordinates -> rasterize your graphics

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