www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/01/18:13:15

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: rotation Q:
Date: Tue, 1 Apr 1997 20:20:14 +0100
Organization: None
Distribution: world
Message-ID: <nrm6NSAu$VQzEwD1@talula.demon.co.uk>
References: <333DF207 DOT 8B3 AT cam DOT org>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
Lines: 37
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Tudor writes:
>I have this Q: How can I do rotations however I want?
>Like ,when I rotate a cube(classic :) I have no ideea after what point
>the cube gets rotated(probably the origin).

Yup, it is indeed the origin...

>Let's say you have a stick and the points A and B are its extremities:
>(C is just another point)
>
> A ----------- B     C  :)
>
>Now you can rotate the stick by the middle and A and B will move in
>opposite directions. You can rotate it after C so A and B will move in
>the same direction. Or you can take any other point to rotate your
>stuff. (the example is stupid but at least it explains what I want)
>How can I do something like this in Allegro?

The trick is to realise that you can put your origin wherever you want.
If you position your stick so that the origin is at B, or C, etc, that
is where it will get rotated around. Of course this will leave the
points in the wrong place relative to the rest of the world, but you can
then just translate them back so it ends up in the right place.

If you want to rotate an object around the point x,y,z, you can
translate it by -x,-y,-z (so that the point x,y,z is moved to 0,0,0),
rotate around the origin, and then translate by x,y,z to shift it back
to the original location. This is where matrices come in really handy:
if you build three matrices for these transformations (two with
get_translation_matrix() and one with get_rotation_matrix()), you can
concatenate them together with the matrix_mul() function, producing a
new matrix that will do all three transformations in a single step!


--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
Beauty is a French phonetic corruption of a short cloth neck ornament.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019