buldthensnip/vecmath.c
2012-11-06 11:58:32 +13:00

67 lines
2.0 KiB
C

/*
This file is part of Iceball.
Iceball is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Iceball is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Iceball. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common.h"
void cam_point_dir(camera_t *model, float dx, float dy, float dz, float zoom, float roll)
{
// Another case where I'd copy-paste code from my aimbot.
// Except the last time I did it, I redid it from scratch,
// and then dumped it. (VUW COMP308 Project 2012T2, anyone?)
//
// But yeah, basically this code's useful for making aimbots >:D
//
// Am I worried?
// Well, the average skid is too lazy to compile this.
// So, uh, no, not really.
// Get two distance values.
float d2 = dx*dx+dz*dz;
float d3 = dy*dy+d2;
// Square root them so they're actually distance values.
d2 = sqrtf(d2);
d3 = sqrtf(d3);
// Get the normalised distances.
float nx = dx/d3;
float ny = dy/d3;
float nz = dz/d3;
// Now build that matrix!
// Front vector (Z): Well, duh.
model->mzx = nx*zoom;
model->mzy = ny*zoom;
model->mzz = nz*zoom;
// Left (TODO: confirm) vector (X): Simple 2D 90deg rotation.
// Can be derived from a bit of trial and error.
model->mxx = dz/d2;
model->mxy = 0.0f;
model->mxz = -dx/d2;
// Down vector (Y): STUPID GIMBAL LOCK GRR >:(
// But really, this one's the hardest of them all.
//
// I decided to cheat and look at my aimbot anyway.
// Still didn't *quite* solve my problem.
model->myx = -dx*ny/d2;
model->myy = sqrtf(1.0f - ny*ny);
model->myz = -dz*ny/d2;
}