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;
}
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;
}