Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use new reciprocal RAD for #197 #251

Merged
merged 2 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/engine/interface/cubestd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1193,13 +1193,13 @@ void initmathcmds()
addcommand("pow", reinterpret_cast<identfun>(+[] (tagval *args, int numargs) { { float val; if(numargs >= 2) { val = args[0].f; float val2 = args[1].f; val = std::pow(val, val2); for(int i = 2; i < numargs; i++) { val2 = args[i].f; val = std::pow(val, val2); } } else { val = numargs > 0 ? args[0].f : 0; ; } floatret(val); }; }), "f" "1V", Id_Command);

//float transcendentals
addcommand("sin", reinterpret_cast<identfun>(+[] (float *a) { floatret(std::sin(*a*RAD)); }), "f", Id_Command);
addcommand("cos", reinterpret_cast<identfun>(+[] (float *a) { floatret(std::cos(*a*RAD)); }), "f", Id_Command);
addcommand("tan", reinterpret_cast<identfun>(+[] (float *a) { floatret(std::tan(*a*RAD)); }), "f", Id_Command);
addcommand("asin", reinterpret_cast<identfun>(+[] (float *a) { floatret(std::asin(*a)/RAD); }), "f", Id_Command);
addcommand("acos", reinterpret_cast<identfun>(+[] (float *a) { floatret(std::acos(*a)/RAD); }), "f", Id_Command);
addcommand("atan", reinterpret_cast<identfun>(+[] (float *a) { floatret(std::atan(*a)/RAD); }), "f", Id_Command);
addcommand("atan2", reinterpret_cast<identfun>(+[] (float *y, float *x) { floatret(std::atan2(*y, *x)/RAD); }), "ff", Id_Command);
addcommand("sin", reinterpret_cast<identfun>(+[] (float *a) { floatret(std::sin(*a/RAD)); }), "f", Id_Command);
addcommand("cos", reinterpret_cast<identfun>(+[] (float *a) { floatret(std::cos(*a/RAD)); }), "f", Id_Command);
addcommand("tan", reinterpret_cast<identfun>(+[] (float *a) { floatret(std::tan(*a/RAD)); }), "f", Id_Command);
addcommand("asin", reinterpret_cast<identfun>(+[] (float *a) { floatret(std::asin(*a)*RAD); }), "f", Id_Command);
addcommand("acos", reinterpret_cast<identfun>(+[] (float *a) { floatret(std::acos(*a)*RAD); }), "f", Id_Command);
addcommand("atan", reinterpret_cast<identfun>(+[] (float *a) { floatret(std::atan(*a)*RAD); }), "f", Id_Command);
addcommand("atan2", reinterpret_cast<identfun>(+[] (float *y, float *x) { floatret(std::atan2(*y, *x)*RAD); }), "ff", Id_Command);
addcommand("sqrt", reinterpret_cast<identfun>(+[] (float *a) { floatret(std::sqrt(*a)); }), "f", Id_Command);
addcommand("loge", reinterpret_cast<identfun>(+[] (float *a) { floatret(std::log(*a)); }), "f", Id_Command);
addcommand("log2", reinterpret_cast<identfun>(+[] (float *a) { floatret(std::log(*a)/M_LN2); }), "f", Id_Command);
Expand Down
2 changes: 1 addition & 1 deletion src/engine/interface/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ bool updatechannel(SoundChannel &chan)
}
if(stereo && (v.x != 0 || v.y != 0) && dist>0)
{
v.rotate_around_z(-camera1->yaw*RAD);
v.rotate_around_z(-camera1->yaw/RAD);
pan = static_cast<int>(255.9f*(0.5f - 0.5f*v.x/v.magnitude2())); // range is from 0 (left) to 255 (right)
}
}
Expand Down
34 changes: 17 additions & 17 deletions src/engine/model/animmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ void animmodel::part::intersect(int anim, int basetime, int basetime2, float pit
{
++matrixpos;
matrixstack[matrixpos] = matrixstack[matrixpos-1];
matrixstack[matrixpos].rotate(pitchamount*RAD, oaxis);
matrixstack[matrixpos].rotate(pitchamount/RAD, oaxis);
}
if(this == model->parts[0] && !model->translate.iszero())
{
Expand Down Expand Up @@ -1059,7 +1059,7 @@ void animmodel::part::render(int anim, int basetime, int basetime2, float pitch,
{
++matrixpos;
matrixstack[matrixpos] = matrixstack[matrixpos-1];
matrixstack[matrixpos].rotate(pitchamount*RAD, oaxis);
matrixstack[matrixpos].rotate(pitchamount/RAD, oaxis);
}
if(this == model->parts[0] && !model->translate.iszero())
{
Expand Down Expand Up @@ -1277,29 +1277,29 @@ int animmodel::intersect(int anim, int basetime, int basetime2, const vec &pos,
roll += spinroll*secs;

matrixstack[0].settranslation(pos);
matrixstack[0].rotate_around_z(yaw*RAD);
matrixstack[0].rotate_around_z(yaw/RAD);
bool usepitch = pitched();
if(roll && !usepitch)
{
matrixstack[0].rotate_around_y(-roll*RAD);
matrixstack[0].rotate_around_y(-roll/RAD);
}
matrixstack[0].transformnormal(vec(axis), axis);
matrixstack[0].transformnormal(vec(forward), forward);
if(roll && usepitch)
{
matrixstack[0].rotate_around_y(-roll*RAD);
matrixstack[0].rotate_around_y(-roll/RAD);
}
if(offsetyaw)
{
matrixstack[0].rotate_around_z(offsetyaw*RAD);
matrixstack[0].rotate_around_z(offsetyaw/RAD);
}
if(offsetpitch)
{
matrixstack[0].rotate_around_x(offsetpitch*RAD);
matrixstack[0].rotate_around_x(offsetpitch/RAD);
}
if(offsetroll)
{
matrixstack[0].rotate_around_y(-offsetroll*RAD);
matrixstack[0].rotate_around_y(-offsetroll/RAD);
}
}
else
Expand Down Expand Up @@ -1436,29 +1436,29 @@ void animmodel::render(int anim, int basetime, int basetime2, const vec &o, floa
roll += spinroll*secs;

matrixstack[0].settranslation(o);
matrixstack[0].rotate_around_z(yaw*RAD);
matrixstack[0].rotate_around_z(yaw/RAD);
bool usepitch = pitched();
if(roll && !usepitch)
{
matrixstack[0].rotate_around_y(-roll*RAD);
matrixstack[0].rotate_around_y(-roll/RAD);
}
matrixstack[0].transformnormal(vec(axis), axis);
matrixstack[0].transformnormal(vec(forward), forward);
if(roll && usepitch)
{
matrixstack[0].rotate_around_y(-roll*RAD);
matrixstack[0].rotate_around_y(-roll/RAD);
}
if(offsetyaw)
{
matrixstack[0].rotate_around_z(offsetyaw*RAD);
matrixstack[0].rotate_around_z(offsetyaw/RAD);
}
if(offsetpitch)
{
matrixstack[0].rotate_around_x(offsetpitch*RAD);
matrixstack[0].rotate_around_x(offsetpitch/RAD);
}
if(offsetroll)
{
matrixstack[0].rotate_around_y(-offsetroll*RAD);
matrixstack[0].rotate_around_y(-offsetroll/RAD);
}
}
else
Expand Down Expand Up @@ -1515,15 +1515,15 @@ void animmodel::initmatrix(matrix4x3 &m)
m.identity();
if(offsetyaw)
{
m.rotate_around_z(offsetyaw*RAD);
m.rotate_around_z(offsetyaw/RAD);
}
if(offsetpitch)
{
m.rotate_around_x(offsetpitch*RAD);
m.rotate_around_x(offsetpitch/RAD);
}
if(offsetroll)
{
m.rotate_around_y(-offsetroll*RAD);
m.rotate_around_y(-offsetroll/RAD);
}
m.translate(translate, scale);
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine/model/ragdoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ void ragdolldata::move(dynent *pl, float ts)
dpos.z -= gravity*ts*ts;
if(water)
{
dpos.z += 0.25f*std::sin(detrnd(size_t(this)+i, 360)*RAD + lastmillis/10000.0f*M_PI)*ts;
dpos.z += 0.25f*std::sin(detrnd(size_t(this)+i, 360)/RAD + lastmillis/10000.0f*M_PI)*ts;
}
dpos.mul(std::pow((water ? ragdollwaterfric : 1.0f) * (v.collided ? ragdollgroundfric : airfric), ts*1000.0f/ragdolltimestepmin)*tsfric);
v.oldpos = v.pos;
Expand Down
10 changes: 5 additions & 5 deletions src/engine/model/skelmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ float skelmodel::skeleton::calcdeviation(const vec &axis, const vec &forward, co
{
dy = -dy;
}
return atan2f(dy, dx)/RAD;
return atan2f(dy, dx)*RAD;
}

void skelmodel::skeleton::calcpitchcorrects(float pitch, const vec &axis, const vec &forward)
Expand Down Expand Up @@ -696,7 +696,7 @@ void skelmodel::skeleton::interpbones(const AnimState *as, float pitch, const ve
{
angle *= (as->cur.anim & Anim_NoPitch ? 0 : as->interp) + (as->interp < 1 && as->prev.anim & Anim_NoPitch ? 0 : 1 - as->interp);
}
sc.bdata[b.interpindex].mulorient(quat(axis, angle*RAD), b.base);
sc.bdata[b.interpindex].mulorient(quat(axis, angle/RAD), b.base);
}
}
for(uint i = 0; i < antipodes.size(); i++)
Expand Down Expand Up @@ -1727,15 +1727,15 @@ void skeladjustment::adjust(dualquat &dq)
{
if(yaw)
{
dq.mulorient(quat(vec(0, 0, 1), yaw*RAD));
dq.mulorient(quat(vec(0, 0, 1), yaw/RAD));
}
if(pitch)
{
dq.mulorient(quat(vec(0, -1, 0), pitch*RAD));
dq.mulorient(quat(vec(0, -1, 0), pitch/RAD));
}
if(roll)
{
dq.mulorient(quat(vec(-1, 0, 0), roll*RAD));
dq.mulorient(quat(vec(-1, 0, 0), roll/RAD));
}
if(!translate.iszero())
{
Expand Down
8 changes: 4 additions & 4 deletions src/engine/model/skelmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ struct skelcommands : modelcommands<MDL, struct MDL::skelmesh>
}
DEF_FORMAT_STRING(filename, "%s/%s", MDL::dir, meshfile);
part &mdl = MDL::loading->addpart();
mdl.meshes = MDL::loading->sharemeshes(path(filename), skelname[0] ? skelname : nullptr, *smooth > 0 ? std::cos(std::clamp(*smooth, 0.0f, 180.0f)*RAD) : 2);
mdl.meshes = MDL::loading->sharemeshes(path(filename), skelname[0] ? skelname : nullptr, *smooth > 0 ? std::cos(std::clamp(*smooth, 0.0f, 180.0f)/RAD) : 2);
if(!mdl.meshes)
{
conoutf("could not load %s", filename);
Expand All @@ -732,9 +732,9 @@ struct skelcommands : modelcommands<MDL, struct MDL::skelmesh>
int i = mdl.meshes ? static_cast<meshgroup *>(mdl.meshes)->skel->findbone(name) : -1;
if(i >= 0)
{
float cx = *rx ? std::cos(*rx/2*RAD) : 1, sx = *rx ? std::sin(*rx/2*RAD) : 0,
cy = *ry ? std::cos(*ry/2*RAD) : 1, sy = *ry ? std::sin(*ry/2*RAD) : 0,
cz = *rz ? std::cos(*rz/2*RAD) : 1, sz = *rz ? std::sin(*rz/2*RAD) : 0;
float cx = *rx ? std::cos(*rx/(2*RAD)) : 1, sx = *rx ? std::sin(*rx/(2*RAD)) : 0,
cy = *ry ? std::cos(*ry/(2*RAD)) : 1, sy = *ry ? std::sin(*ry/(2*RAD)) : 0,
cz = *rz ? std::cos(*rz/(2*RAD)) : 1, sz = *rz ? std::sin(*rz/(2*RAD)) : 0;
matrix4x3 m(matrix3(quat(sx*cy*cz - cx*sy*sz, cx*sy*cz + sx*cy*sz, cx*cy*sz - sx*sy*cz, cx*cy*cz + sx*sy*sz)),
vec(*tx, *ty, *tz));
static_cast<meshgroup *>(mdl.meshes)->skel->addtag(tagname, i, m);
Expand Down
14 changes: 7 additions & 7 deletions src/engine/model/vertmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ struct vertcommands : modelcommands<MDL, struct MDL::vertmesh>
{
mdl.disablepitch();
}
mdl.meshes = MDL::loading->sharemeshes(path(filename), *smooth > 0 ? std::cos(std::clamp(*smooth, 0.0f, 180.0f)*RAD) : 2);
mdl.meshes = MDL::loading->sharemeshes(path(filename), *smooth > 0 ? std::cos(std::clamp(*smooth, 0.0f, 180.0f)/RAD) : 2);
if(!mdl.meshes)
{
conoutf("could not load %s", filename);
Expand All @@ -290,12 +290,12 @@ struct vertcommands : modelcommands<MDL, struct MDL::vertmesh>
return;
}
part &mdl = *static_cast<part *>(MDL::loading->parts.last());
float cx = *rx ? std::cos(*rx/2*RAD) : 1,
sx = *rx ? std::sin(*rx/2*RAD) : 0,
cy = *ry ? std::cos(*ry/2*RAD) : 1,
sy = *ry ? std::sin(*ry/2*RAD) : 0,
cz = *rz ? std::cos(*rz/2*RAD) : 1,
sz = *rz ? std::sin(*rz/2*RAD) : 0;
float cx = *rx ? std::cos(*rx/(2*RAD)) : 1,
sx = *rx ? std::sin(*rx/(2*RAD)) : 0,
cy = *ry ? std::cos(*ry/(2*RAD)) : 1,
sy = *ry ? std::sin(*ry/(2*RAD)) : 0,
cz = *rz ? std::cos(*rz/(2*RAD)) : 1,
sz = *rz ? std::sin(*rz/(2*RAD)) : 0;
//matrix m created from (matrix3 created from quat) + (vec) appended afterwards
matrix4x3 m(static_cast<matrix3>(quat(sx*cy*cz - cx*sy*sz,
cx*sy*cz + sx*cy*sz,
Expand Down
4 changes: 2 additions & 2 deletions src/engine/render/csm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ void cascadedshadowmap::updatesplitdist()
void cascadedshadowmap::getmodelmatrix()
{
model = viewmatrix;
model.rotate_around_x(sunlightpitch*RAD);
model.rotate_around_z((180-sunlightyaw)*RAD);
model.rotate_around_x(sunlightpitch/RAD);
model.rotate_around_z((180-sunlightyaw)/RAD);
}

void cascadedshadowmap::getprojmatrix()
Expand Down
8 changes: 4 additions & 4 deletions src/engine/render/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace
matrix4x3 m;
m.identity();
m.settranslation(w/2, h/2, 0);
m.rotate_around_z(i*45*RAD);
m.rotate_around_z(i*45/RAD);
m.translate(0, offset, 0);
m.scale(size*scale);

Expand Down Expand Up @@ -424,8 +424,8 @@ void vectoryawpitch(const vec &v, float &yaw, float &pitch)
}
else
{
yaw = -std::atan2(v.x, v.y)/RAD;
pitch = std::asin(v.z/v.magnitude())/RAD;
yaw = -std::atan2(v.x, v.y)*RAD;
pitch = std::asin(v.z/v.magnitude())*RAD;
}
}

Expand Down Expand Up @@ -478,4 +478,4 @@ void inithudcmds()
{
addcommand("loadcrosshair", reinterpret_cast<identfun>(+[](const char *name, int *i){loadcrosshair(name, *i);}), "si", Id_Command);
addcommand("getcrosshair", reinterpret_cast<identfun>(getcrosshair), "i", Id_Command);
}
}
4 changes: 2 additions & 2 deletions src/engine/render/octarender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2214,8 +2214,8 @@ ushort encodenormal(const vec &n)
{
return 0;
}
int yaw = static_cast<int>(-std::atan2(n.x, n.y)/RAD), //arctangent in degrees
pitch = static_cast<int>(std::asin(n.z)/RAD); //arcsin in degrees
int yaw = static_cast<int>(-std::atan2(n.x, n.y)*RAD), //arctangent in degrees
pitch = static_cast<int>(std::asin(n.z)*RAD); //arcsin in degrees
return static_cast<ushort>(std::clamp(pitch + 90, 0, 180)*360 + (yaw < 0 ? yaw%360 + 360 : yaw%360) + 1);
}

Expand Down
4 changes: 2 additions & 2 deletions src/engine/render/radiancehints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,8 @@ void reflectiveshadowmap::setup()
void reflectiveshadowmap::getmodelmatrix()
{
model = viewmatrix; //copy global view matrix
model.rotate_around_x(sunlightpitch*RAD); //orient camera in same yaw as sunlight
model.rotate_around_z((180-sunlightyaw)*RAD); //orient camera in same pitch as sunlight
model.rotate_around_x(sunlightpitch/RAD); //orient camera in same yaw as sunlight
model.rotate_around_z((180-sunlightyaw)/RAD); //orient camera in same pitch as sunlight
}

void reflectiveshadowmap::getprojmatrix()
Expand Down
20 changes: 10 additions & 10 deletions src/engine/render/rendergl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,9 @@ void setcammatrix()
{
// move from RH to Z-up LH quake style worldspace
cammatrix = viewmatrix;
cammatrix.rotate_around_y(camera1->roll*RAD);
cammatrix.rotate_around_x(camera1->pitch*-RAD);
cammatrix.rotate_around_z(camera1->yaw*-RAD);
cammatrix.rotate_around_y(camera1->roll/RAD);
cammatrix.rotate_around_x(camera1->pitch/-RAD);
cammatrix.rotate_around_z(camera1->yaw/-RAD);
cammatrix.translate(vec(camera1->o).neg());

cammatrix.transposedtransformnormal(vec(viewmatrix.b), camdir);
Expand Down Expand Up @@ -896,7 +896,7 @@ float calcfrustumboundsphere(float nearplane, float farplane, const vec &pos, c
return minimapradius.magnitude();
}

float width = std::tan(fov/2.0f*RAD),
float width = std::tan(fov/(2.0f*RAD)),
height = width / aspect,
cdist = ((nearplane + farplane)/2)*(1 + width*width + height*height);
if(cdist <= farplane)
Expand All @@ -919,7 +919,7 @@ vec calcavatarpos(const vec &pos, float dist)
{
vec eyepos;
cammatrix.transform(pos, eyepos);
GLdouble ydist = nearplane * std::tan(curavatarfov/2*RAD),
GLdouble ydist = nearplane * std::tan(curavatarfov/(2*RAD)),
xdist = ydist * aspect;
vec4<float> scrpos;
scrpos.x = eyepos.x*nearplane/xdist;
Expand Down Expand Up @@ -1020,7 +1020,7 @@ bool calcspherescissor(const vec &center, float size, float &sx1, float &sy1, fl
float zzrr = e.z*e.z - size*size,
dx = e.x*e.x + zzrr,
dy = e.y*e.y + zzrr,
focaldist = 1.0f/std::tan(fovy*0.5f*RAD);
focaldist = 1.0f/std::tan(fovy*0.5f/RAD);
sx1 = sy1 = -1;
sx2 = sy2 = 1;
#define CHECKPLANE(c, dir, focaldist, low, high) \
Expand Down Expand Up @@ -1694,7 +1694,7 @@ void ModelPreview::start(int xcoord, int ycoord, int width, int height, bool bg,

aspect = w/static_cast<float>(h);
fovy = modelpreviewfov;
curfov = 2*std::atan2(std::tan(fovy/2*RAD), 1/aspect)/RAD;
curfov = 2*std::atan2(std::tan(fovy/(2*RAD)), 1/aspect)*RAD;
farplane = 1024;
vieww = std::min(gw, w);
viewh = std::min(gh, h);
Expand Down Expand Up @@ -1736,8 +1736,8 @@ void ModelPreview::end()
vec calcmodelpreviewpos(const vec &radius, float &yaw)
{
yaw = std::fmod(lastmillis/10000.0f*360.0f, 360.0f);
float dist = std::max(radius.magnitude2()/aspect, radius.magnitude())/std::sin(fovy/2*RAD);
return vec(0, dist, 0).rotate_around_x(camera1->pitch*RAD);
float dist = std::max(radius.magnitude2()/aspect, radius.magnitude())/std::sin(fovy/(2*RAD));
return vec(0, dist, 0).rotate_around_x(camera1->pitch/RAD);
}

int xtraverts, xtravertsva;
Expand Down Expand Up @@ -1912,7 +1912,7 @@ void gl_drawframe(int crosshairindex, void (*gamefxn)(), void (*hudfxn)(), void
xtravertsva = xtraverts = glde = gbatches = vtris = vverts = 0;
flipqueries();
aspect = forceaspect ? forceaspect : hudw/static_cast<float>(hudh);
fovy = 2*std::atan2(std::tan(curfov/2*RAD), aspect)/RAD;
fovy = 2*std::atan2(std::tan(curfov/(2*RAD)), aspect)*RAD;
vieww = hudw;
viewh = hudh;
if(mainmenu)
Expand Down
Loading