It looks like you're new here. If you want to get involved, click one of these buttons!

- 140.3K All Categories
- 104.2K Programming Languages
- 6.3K Assembler Developer
- 1.8K Basic
- 39.7K C and C++
- 4.2K C#
- 7.9K Delphi and Kylix
- 3 Haskell
- 9.6K Java
- 4.1K Pascal
- 1.3K Perl
- 1.9K PHP
- 502 Python
- 47 Ruby
- 4.3K VB.NET
- 1.6K VBA
- 20.8K Visual Basic
- 2.6K Game programming
- 308 Console programming
- 88 DirectX Game dev
- 1 Minecraft
- 108 Newbie Game Programmers
- 2 Oculus Rift
- 8.9K Applications
- 1.8K Computer Graphics
- 726 Computer Hardware
- 3.4K Database & SQL
- 519 Electronics development
- 1.6K Matlab
- 627 Sound & Music
- 253 XML Development
- 3.2K Classifieds
- 189 Co-operative Projects
- 169 For sale
- 189 FreeLance Software City
- 1.9K Jobs Available
- 598 Jobs Wanted
- 196 Wanted
- 2.9K Microsoft .NET
- 1.7K ASP.NET
- 1.1K .NET General
- 2.9K Miscellaneous
- 3 Join the Team
- 2 User Profiles
- 352 Comments on this site
- 56 Computer Emulators
- 1.7K General programming
- 136 New programming languages
- 598 Off topic board
- 158 Mobile & Wireless
- 32 Android
- 124 Palm Pilot
- 334 Multimedia
- 151 Demo programming
- 183 MP3 programming
- 0 Bash scripts
- 15 Cloud Computing
- 52 FreeBSD
- 1.7K LINUX programming
- 363 MS-DOS
- 0 Shell scripting
- 318 Windows CE & Pocket PC
- 4.1K Windows programming
- 876 Software Development
- 401 Algorithms
- 67 Object Orientation
- 81 Project Management
- 88 Quality & Testing
- 232 Security
- 7.5K WEB-Development
- 1.8K Active Server Pages
- 61 AJAX
- 2 Bootstrap Themes
- 55 CGI Development
- 19 ColdFusion
- 221 Flash development
- 1.4K HTML & WEB-Design
- 1.4K Internet Development
- 2.2K JavaScript
- 33 JQuery
- 282 WEB Servers
- 107 WEB-Services / SOAP

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Lopez
Posts: **75**Member

I've coded a 3D plotter, which takes the 3 x,y,z co-ordinates and puts them to the screen. I've made a cube but I can only move the camera x,y,z I want to make the camera be able to rotate it's viewpoint along x axis (or y axis, both are the same), what is the technique for doing this?

or the technique for rotating the cube?

Someone must know the technique, I've seen so many rotating cube demos in my life. Does it involve the equation of a circle?

or the technique for rotating the cube?

Someone must know the technique, I've seen so many rotating cube demos in my life. Does it involve the equation of a circle?

About & Contact / Terms of use / Privacy statement / Publisher: Lars Hagelin

Programmers Heaven articles / Programmers Heaven files / Programmers Heaven uploaded content / Programmers Heaven C Sharp ebook / Operated by CommunityHeaven LLC

© 1997-2013 Programmersheaven.com - All rights reserved.

## Comments

75MemberUm, I think this is right anyway, see if I can get it right now.

- Spam

0 · Vote Down Vote Up · Share on Facebook22MemberA little trig:

x=r*cos(a)

y=r*sin(a)

[x^2+y^2=(r*cos(a))^2+(r*sin(a))^2 ;normal/polar circle eq]

Now we do a rotation of angle b:

x=r*cos(a+b); [cos(a+b)=cos(a)*cos(b)-sin(a)*sin(b)]

y=r*sin(a+b); [sin(a+b)=sin(a)*cos(b)+cos(a)*sin(b)]

x=r*cos(a)+cos(b)-r*sin(a)*sin(b); [r*cos(a)=x, r*sin(a)=y]

y=r*sin(a)+cos(b)+r*cos(a)*sin(b); [r*cos(a)=x, r*sin(a)=y]

Finally:

x=x*cos(b)-y*sin(b)

y=x*sin(b)+y*cos(b)

Now if we look from -Z to +Z we see:

X

|_Y 2Dplane(x,y)

From -X to +X:

Z

|_Y 2Dplane(y,z)

From -Y to +Y:

X

|_Z 2Dplane(z,x)

Then the rotation around X-Axis of angle ax:

x=x

y=y*cos(ax)-z*sin(ax)

z=y*sin(ax)+z*cos(ax)

Y-Axis ay:

x=z*sin(ay)+x*cos(ay)

y=y

z=z*cos(ay)-x*sin(ay)

Z-Axis az:

x=x*cos(az)-y*sin(az)

y=x*sin(az)+y*cos(az)

z=z

2-Axis rotation takes: 8 mul, 2 add, 2 sub per point

Rotate of 25 on ax then 30 on ay, or first 30 on ay then 25 on ax dont change the result, so the order we rotate ours point dont actually matter.

Matrix: Rotate using a matrix

Z-Axis: (that u dont need but it's simple to understand)

x=x*( cos(az)) + y*(-sin(az)) + z*0

y=x*( sin(az)) + y*( cos(az)) + z*0

z=x*0 + y*0 + z*1

This sys of eq. can be express as the multiplication betwenn a 3x3 matrix and a 3D vector:

V'=Rz*V; [Rz:matrix, V:vector, V':rotated vector]

The coefficent of Rz are:

Rz0=cos(az), Rz1=-sin(az), Rz2=0,

Rz3=sin(az), Rz4=cos(az), Rz5=0,

Rz6=0, Rz7=0, Rz8=1

where:

x = x*Rz0 + y*Rz1 + z*Rz2

y = x*Rz3 + y*Rz4 + z*Rz5

z = x*Rz6 + y*Rz7 + z*Rz8

The coefficent of Ry:

Ry0=cos(ay), Rz1=0, Rz2=sin(ay),

Ry3=0, Rz4=1, Rz5=0,

Ry6=-sin(ay), Rz7=0, Rz8=cos(ay)

The coefficent of Rx:

Rx0=1, Rz1=0, Rz2=0,

Rx3=0, Rz4=cos(ax), Rz5=-sin(ax),

Rx6=0, Rz7=sin(ax), Rz8=cos(ay)

The multiplication of two matrixs create a thirth matrix that does the both 3d trasformation in the order of the multiplication, with rotation dosn't really matter but with matrixs u can perfor other 3D traformation where the order is important indeed.

Rx*Ry=Rxy:

Rxy0 = Rx0*Ry0 + Rx1*Ry3 + Rx2*Ry6

Rxy1 = Rx0*Ry1 + Rx1*Ry4 + Rx2*Ry7

Rxy2 = Rx0*Ry2 + Rx1*Ry5 + Rx2*Ry8

Rxy3 = Rx3*Ry0 + Rx4*Ry3 + Rx5*Ry6

Rxy4 = Rx3*Ry1 + Rx4*Ry4 + Rx5*Ry7

Rxy5 = Rx3*Ry2 + Rx4*Ry5 + Rx5*Ry8

Rxy6 = Rx6*Ry0 + Rx7*Ry3 + Rx8*Ry6

Rxy7 = Rx6*Ry1 + Rx7*Ry4 + Rx8*Ry7

Rxy8 = Rx6*Ry2 + Rx7*Ry5 + Rx8*Ry8

Ok sounds bad but it isn't really

Rxy0=cos(ay)

Rxy1=0

Rxy2=sin(ay)

Rxy3=sin(ax)*sin(ay)

Rxy4=cos(ax)

Rxy5=-sin(ax)*cos(ay)

Rxy6=-cos(ax)*sin(ay)

Rxy7=sin(ax)

Rxy8=cos(ax)*cos(ay)

where:

x = x*Rxy0 + y*0 + z*Rxy2 = x*Rxy0 + z*Rxy2

y = x*Rxy3 + y*Rxy4 + z*Rxy5

z = x*Rxy6 + y*Rxy7 + z*Rxy8

2-Axis matrix rotation takes: 8 mul, 5 add per point

The camera:

The rotation for the camera it's done in the same way, but we need to rotate the world around the negative camera's angles.

Just need to know that: cos(-a)=cos(a), sin(-a)=-sin(a)

cam_Rxy0=cos(ay)

cam_Rxy1=0

cam_Rxy2=-sin(ay)

cam_Rxy3=sin(ax)*sin(ay)

cam_Rxy4=cos(ax)

cam_Rxy5=sin(ax)*cos(ay)

cam_Rxy6=cos(ax)*sin(ay)

cam_Rxy7=-sin(ax)

cam_Rxy8=cos(ax)*cos(ay)

Here the matrix's way seems to be more complicated without gaining speed from it, but where u will facing 3-axis matrix rotation, then later use to describe on a 3d space an object or a camera a 4x4 matrix, it will be clear that the matrix's way is much better.

I suggest you to use and learn how to handle it.

Mutilate[OA]

- Spam

0 · Vote Down Vote Up · Share on Facebook