Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Projecting 3D object to 2D plane

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Polynomial
Grandmaster Cheater
Reputation: 5

Joined: 17 Feb 2008
Posts: 524
Location: Inside the Intel CET shadow stack

PostPosted: Wed Sep 15, 2010 8:48 am    Post subject: Projecting 3D object to 2D plane Reply with quote

I'm working on some C# code that uses GDI to display some graphics, and I'd like to draw a '3D' cube using some projection math. The basic idea is that given a set of points in 3D space and a viewplane (i.e. a camera) you can create a 2D image displaying the 3D object. DirectX and OpenGL do these transformations. I believe it's known as Perspective Projection.

What I can't figure out is exactly how this math is done. I've read up on Wikipedia, but they go full frontal crazy with matrix multiplication.

Does anyone know how to do it? It's driving me insane.

_________________
It's not fun unless every exploit mitigation is enabled.
Please do not reply to my posts with LLM-generated slop; I consider it to be an insult to my time.
Back to top
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 893

PostPosted: Wed Sep 15, 2010 10:19 am    Post subject: Reply with quote

If you're doing raster graphics, the best way to get started (IMHO) is to simply omit the depth coordinates. This is the simplest form of projection (orthographic).

Once you can spin a cube around in such a fashion, the need for something more sophisticated will probably become evident - you have to compensate for the fact that distant objects appear smaller. One approach you could try would be to scale points according to their depth. This works, but only for objects that are viewed from one perspective (directly overhead). Start moving things around, and you introduce distortion.

The generally approved approach is to "project" objects using a plane some distance from the viewpoint and scaling according to distance from the plane rather than depth from the viewpoint. To calculate the projection, you pass a ray from the viewpoint to the point to be drawn and look at its intersection with the plane. This is where the trig comes into play. You can absolutely do this process without matrices, but there's no way to avoid the trig.

I'm terrible at explaining this because I'm fairly awful at implementing it. Make sense, though?

Cheers,
adude
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Wed Sep 15, 2010 12:49 pm    Post subject: Reply with quote

Slovach has done exactly what you are trying to do and released his source.

Link to the thread
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Sep 15, 2010 1:42 pm    Post subject: Re: Projecting 3D object to 2D plane Reply with quote

Burningmace wrote:
I'm working on some C# code that uses GDI to display some graphics, and I'd like to draw a '3D' cube using some projection math. The basic idea is that given a set of points in 3D space and a viewplane (i.e. a camera) you can create a 2D image displaying the 3D object. DirectX and OpenGL do these transformations. I believe it's known as Perspective Projection.

What I can't figure out is exactly how this math is done. I've read up on Wikipedia, but they go full frontal crazy with matrix multiplication.

Does anyone know how to do it? It's driving me insane.


The matrix stuff is pretty simple, as far as you need to know, at it's most basic level, it's just an object that can handle / hold translation, rotation, and scaling of an object. In this case, it's a 4x4 array that holds numbers. Probably the most important operation you'll be doing on them is concatenation.

http://msdn.microsoft.com/en-us/library/bb153311%28v=VS.85%29.aspx


Once you get your matricies setup, everything should be fairly simple.
http://msdn.microsoft.com/en-us/library/ee418867%28VS.85%29.aspx

I create a perspective matrix:
http://msdn.microsoft.com/en-us/library/bb205350%28v=VS.85%29.aspx

and create a world matrix:
... which is just a matrix set to its identity (for now). I never bothered setting up a view matrix because I was lazy, so I just move the actual world itself.

From there it's pretty straightforward
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites