50 lines
1.3 KiB
C
50 lines
1.3 KiB
C
#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;
|
|
}
|