PDA

View Full Version : 3d rotation


FireSlash
26th Jul 2003, 07:52 AM
Do these functions look right? Every time I try to rotate using these function, the model gets skewed.
x,y,z are the coordinates of the current vertex, and rotposx, rotposy, and rotposz are the coordinates of the rotation point.
function rotx($deg) {
$ang = deg2rad($deg);
$a = $this->x-$this->rotposx;
$b = $this->y-$this->rotposy;
$c = $this->z-$this->rotposz;
$x = $a;
$y = $b*cos($ang) + $c*sin($ang);
$z = -$b*sin($ang) + $c*cos($ang);
$this->x = $x+$this->rotposx;
$this->y = $y+$this->rotposy;
$this->z = $z+$this->rotposz;
return;
}
function roty($deg) {
$ang = deg2rad($deg);
$a = $this->x-$this->rotposx;
$b = $this->y-$this->rotposy;
$c = $this->z-$this->rotposz;
$x = $a*cos($ang) - $c*sin($ang);
$y = $b;
$z = $a*sin($ang) + $c*cos($ang);
$this->x = $x+$this->rotposx;
$this->y = $y+$this->rotposy;
$this->z = $z+$this->rotposz;
return;
}

FireSlash
26th Jul 2003, 08:25 AM
Errr... nevermind. I wasn't applying the scaling to the Z coords:rolleyes:


Now, how the HELL am I suppose to implement depth checking? :o

iridium
8th Aug 2003, 12:00 PM
There is a PHP3D lib out there somewhere. I wrote a *.ase parser and used the 3d lib to render it :)

Dunno what you mean by depth checking, might be able to help you if you told me what it is

FireSlash
8th Aug 2003, 12:28 PM
For instance, look how the flak shell is drawn on top of the cannon casing, despite the fact that its inside it on the actual model.