⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 plotting 3d points onto a 2d screen.mht

📁 二维屏幕上表现三维点的绘制方法——适合图形编程的数字运算方法原理
💻 MHT
📖 第 1 页 / 共 2 页
字号:
From: <由 Microsoft Internet Explorer 5 保存>
Subject: Plotting 3D Points onto a 2D screen
Date: Tue, 25 Jul 2006 09:33:38 +0800
MIME-Version: 1.0
Content-Type: multipart/related;
	type="text/html";
	boundary="----=_NextPart_000_001B_01C6AFCD.687C4950"
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180

This is a multi-part message in MIME format.

------=_NextPart_000_001B_01C6AFCD.687C4950
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://freespace.virgin.net/hugo.elias/routines/3d_to_2d.htm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Plotting 3D Points onto a 2D screen</TITLE>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3D"MSHTML 6.00.2900.2180" name=3DGENERATOR></HEAD>
<BODY =
background=3Dhttp://freespace.virgin.net/hugo.elias/routines/paper.jpg>
<P align=3Dcenter><BIG><BIG><STRONG>Plotting 3D Points onto a 2D=20
screen</STRONG></BIG></BIG></P>
<HR>

<P>This is a very useful and quick way to draw 3D point onto your =
screen.</P>
<TABLE cellPadding=3D10 width=3D"100%" border=3D1>
  <TBODY>
  <TR>
    <TD width=3D"100%">
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>screen.x=20
      =3D x / z * zoom</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>screen.y=20
      =3D y / z * zoom</STRONG></P></TD></TR></TBODY></TABLE>
<P>This will produce the screen coordinates of the 3D point. <IMG =
height=3D235=20
alt=3D"graphic1.gif (2744 bytes)"=20
src=3D"http://freespace.virgin.net/hugo.elias/routines/graphic1.gif"=20
width=3D425></P>
<P><STRONG>zoom</STRONG> is the&nbsp; is the distance beetween the =
origin and=20
the 45=B0 mark. By altering the zoom, or changing it independantly for =
the x and y=20
lines, effects like fish eye can be produced.</P>
<P><STRONG>x</STRONG>, <STRONG>y</STRONG> and <STRONG>z</STRONG> are the =
3D=20
coordinates of the point, <STRONG>screen.x</STRONG> and=20
<STRONG>screen.y</STRONG> are the 2D coordinates of the point as it =
would appear=20
on the screen.</P>
<P>This rountine assumes that the centre of your screen is the origin. =
So that=20
coordinates (0, 0) are in the centre of your screen. However, =
practically, you=20
will never be in a situation with a PC, where the origin is in the =
centre of the=20
screen, it is always at the top right hand corner. So to compensate, =
half the=20
screen's width and height must be added. That is that if you have a =
screen=20
resulution of 640x480, your<STRONG> centre</STRONG> will be (320, 240). =
So that=20
must be added to the routine.</P>
<TABLE cellPadding=3D10 width=3D"100%" border=3D1>
  <TBODY>
  <TR>
    <TD width=3D"100%">
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>screen.x=20
      =3D x / z * zoom + centre.x</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>screen.y=20
      =3D y / z * zoom + centre.y</STRONG></P></TD></TR></TBODY></TABLE>
<P=20
style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px">The=20
camera in this routine is looking straight down the <STRONG>z</STRONG> =
axis with=20
<STRONG>x</STRONG> for left and right, and <STRONG>y</STRONG> for up and =
down.=20
If <STRONG>z</STRONG> is negative, the point will be behind the camera, =
and so=20
will not be visible, so this must be added to the routine.</P>
<P=20
style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px">&nbsp;</P>
<TABLE cellPadding=3D10 width=3D"100%" border=3D1>
  <TBODY>
  <TR>
    <TD width=3D"100%">
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>if=20
      z &gt; 0 then</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>&nbsp;&nbsp;&nbsp;=20
      screen.x =3D x / z * zoom + centre.x</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>&nbsp;&nbsp;&nbsp;=20
      screen.y =3D y / z * zoom + centre.y</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>end=20
      if</STRONG></P></TD></TR></TBODY></TABLE>
<P=20
style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px">&nbsp;</P>
<P=20
style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px">If=20
the camera has to move about, and change angle, every coordinate =
entering this=20
routine must be transformed. I will use <STRONG>position</STRONG> for =
the=20
position of the camera, and <STRONG>pan </STRONG>for the camera panning, =
and=20
<STRONG>new</STRONG> just for temporary calculations. </P>
<P=20
style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><IMG=20
height=3D232 alt=3D"graphic2.gif (2478 bytes)"=20
src=3D"http://freespace.virgin.net/hugo.elias/routines/graphic2.gif"=20
width=3D252></P>
<P=20
style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px">These=20
are the axises for <STRONG>pan</STRONG></P>
<TABLE cellPadding=3D15 width=3D"100%" border=3D1>
  <TBODY>
  <TR>
    <TD width=3D"100%">
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>procedure=20
      3Dto2D (x, y, z, pan, centre, position)</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px">&nbsp;</P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>x=20
      =3D x + position.x</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>y=20
      =3D y + position.y</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>z=20
      =3D z + position.z</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px">&nbsp;</P><B>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"></B><STRONG>new.x=20
      =3D x*cos(pan.x) - z*sin(pan.x)</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>new.z=20
      =3D x*sin(pan.x) + z*cos(pan.x)</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>new.y=20
      =3D y*cos(pan.y) - new.z*sin(pan.y)</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>z=20
      =3D new.y*cos(pan.y) - new.z*sin(pan.y)</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>x=20
      =3D new.x*cos(pan.z) - new.y*sin(pan.z)</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>y=20
      =3D new.x*sin(pan.z) + new.y*cos(pan.z)</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px">&nbsp;</P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>if=20
      z &gt; 0 then</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>&nbsp;&nbsp;&nbsp;=20
      screen.x =3D x / z * zoom + centre.x</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>&nbsp;&nbsp;&nbsp;=20
      screen.y =3D y / z * zoom + centre.y</STRONG></P>
      <P=20
      style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px"><STRONG>end=20
      if</STRONG></P></TD></TR></TBODY></TABLE>
<P>To create 3D triangles, quads and polygons all you need do is produce =
several=20
of these points, and join them together.</P>
<HR>

<P><A href=3D"http://freespace.virgin.net/hugo.elias"><IMG=20
src=3D"http://freespace.virgin.net/hugo.elias/flagsmal.gif" border=3D0> =
Return to=20
the Good Looking Textured Light Sourced Bouncy Fun Smart and Stretchy=20
Page.</A></P>
<P=20
style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px">&nbsp;</P>
<P=20
style=3D"MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; PADDING-BOTTOM: 0px; =
PADDING-TOP: 0px">&nbsp;</P>
<P>&nbsp;</P></BODY></HTML>

------=_NextPart_000_001B_01C6AFCD.687C4950
Content-Type: image/gif
Content-Transfer-Encoding: base64
Content-Location: http://freespace.virgin.net/hugo.elias/routines/graphic1.gif

R0lGODlhqQHrAJEAAB8aFzJNlvr4y////yH5BAkAAAEALAAAAACpAesAAAj+AAMIHEiwoMGDCBMq
XMiwocOHECNKnEixosWLGDNq3Mgx4oABHUOKHEmypMmTKFOqXMmypUuXAF7KnEmzps2bOF/GzMmz

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -