Hmm... So I was trying to figure out how to display a cube that could be rotated in all directions. I want to find a formula that converts an (x,y,z) coordinate to an (x,y) coordinate. However hard I looked online, I could not find such a thing. Any help would be welcome.

The screen I am using is 320x240, but any example would be fine, just so that I could grasp the concept.
That looks like the calc screen size...

Short version:
x2d = xOffset + scale * x3d / ( z3d + distanceFromCamera)
y2d = yOffset + scale * y3d / ( z3d + distanceFromCamera)

Long version:
Read this article that I grabbed the earlier code from.

I also delved into the world of 3D myself, and even made a calculator thingie from it! link here
Frankly understanding how 3D -> 2D works without having experience with something like openGL or directx cab be daunting, but basically:

Step 1: all 3D input points are transformed and rotated based on the players position and rotation. Thus, instead of being relative to the world or model origin, these points are now relative to the player. (Vertex shader on modern GPUs)

Step 2: these player-relative 3D points are then projected into 2D.

Step 1 is done with trigonometry, look up "rotating a point in 3D space" if you need help. Step 2 is done with the above posted formula, plus some more math to take care of FOV.
EDIT: check out this neat gif

It's not rotating correctly because ICE doesn't support sine or cosine Sad

Thanks for all the help! I think I have this working, but I need to figure out rotation to see if it is actually doing what it's supposed to.

Here is a screenshot:


And the code (in ICE):

Code:

iCUBE
det(0
det(5,0
det(2,255
For(X,1,8
0→L₁(X)→L₂(X)→L₃(X)→L₄(X)→L₅(X)
End
0→L₁(1)→L₁(3)→L₁(5)→L₁(7)
1→L₁(2)→L₁(4)→L₁(6)→L₁(8)
0→L₂(1)→L₂(2)→L₂(5)→L₂(6)
1→L₂(3)→L₂(4)→L₂(7)→L₂(8)
0→L₃(1)→L₃(2)→L₃(3)→L₃(4)
1→L₃(5)→L₃(6)→L₃(7)→L₃(8)
For(A,1,8
50+50*L₁(A)/(L₃(A)+2)→L₄(A)
50+50*L₂(A)/(L₃(A)+2)→L₅(A)
End
det(30,L₄(1),L₅(1),L₄(2),L₅(2)
det(30,L₄(2),L₅(2),L₄(6),L₅(6)
det(30,L₄(6),L₅(6),L₄(5),L₅(5)
det(30,L₄(5),L₅(5),L₄(1),L₅(1)

det(30,L₄(3),L₅(3),L₄(4),L₅(4)
det(30,L₄(4),L₅(4),L₄(8),L₅(8)
det(30,L₄(8),L₅(8),L₄(7),L₅(7)
det(30,L₄(7),L₅(7),L₄(3),L₅(3)

det(30,L₄(1),L₅(1),L₄(3),L₅(3)
det(30,L₄(2),L₅(2),L₄(4),L₅(4)
det(30,L₄(6),L₅(6),L₄(8),L₅(8)
det(30,L₄(5),L₅(5),L₄(7),L₅(7)

Pause
det(1)

You can't do rotation properly without sin(). Use a look up table I guess?
I actually quite like the above gif, even if it isn't fully accurate to 3D
You can also use a Taylor Series to approximate sine and cosine.
sin(x) = x - (x^3)/(3!) + (x^5)/(5!) - (x^7)/(7!) ... (-1)^n * (x^(2n+1))/((2n+1)!)
cos(x) = 1 - (x^2)/(2!) + (x^4)/(4!) - (x^6)/(6!) ... (-1)^n * (x^(2n))/((2n)!)
Just extend the series as long as necessary.
I am interested in using the Taylor series, however I am confused about how to go about doing so. I assume I choose a finite number of terms, the more terms added the more accurate. After searching online about the Taylor series, I saw nothing like (-1)^n * (x^(2n+1))/((2n+1)!), and just the other parts of the series don't seem to give something similar to sine. Is the bit at the end added to the rest? Where does it fit in (i.e what does '...' represent)? I assume n is the number of factorials used.
Also, a new gif that looks a ton better (I used double buffer PT Very Happy)
_iPhoenix_ wrote:

Short version:
x2d = xOffset + scale * x3d / ( z3d + distanceFromCamera)
y2d = yOffset + scale * y3d / ( z3d + distanceFromCamera)

Long version:
Read this article that I grabbed the earlier code from.
link here


to simplify things a little bit you could just say this --->>
x = x / z
y = y / z
kotu wrote:
_iPhoenix_ wrote:

Short version:
x2d = xOffset + scale * x3d / ( z3d + distanceFromCamera)
y2d = yOffset + scale * y3d / ( z3d + distanceFromCamera)

Long version:
Read this article that I grabbed the earlier code from.
link here


to simplify things a little bit you could just say this --->>
x = x / z
y = y / z

No scale is to make the FOV correct :V
The +distancefromcamera isn't needed though, as all rotation and translation should be done before projection, but it works for a quick demo.
dankcalculatorbro wrote:
After searching online about the Taylor series, I saw nothing like (-1)^n * (x^(2n+1))/((2n+1)!), and just the other parts of the series don't seem to give something similar to sine. Is the bit at the end added to the rest? Where does it fit in (i.e what does '...' represent)? I assume n is the number of factorials used.


Basically, it means that the series continues infinitely following the rule (-1)^n * (x^(2n+1))/((2n+1)!), where n is the place in the series.

For example, the series 1x^2 + 2x^3 + ... nx^(n+1) can be expanded to be 1x^2 + 2x^3 + 3x^4 + 4x^5... nx^(n+1), as the terms I added follow the rule nx^(n+1), and n incremented by 1.

note to self: power rule is great for demos
_iPhoenix:

The link you posted was extremely good... thanks, Dik
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
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

 

Advertisement