Exemplo n.º 1
0
kexVec3 kexVec3::ScreenProject(kexMatrix &proj, kexMatrix &model,
                               const int width, const int height,
                               const int wx, const int wy) {
    kexVec4 projVec;
    kexVec4 modelVec;

    modelVec.ToVec3() = *this;
    modelVec |= model;

    projVec = (modelVec | proj);
    projVec.x *= modelVec.w;
    projVec.y *= modelVec.w;
    projVec.z *= modelVec.w;

    if(projVec.w != 0) {
        projVec.w = 1.0f / projVec.w;
        projVec.x *= projVec.w;
        projVec.y *= projVec.w;
        projVec.z *= projVec.w;

        return kexVec3(
            (projVec.x * 0.5f + 0.5f) * width + wx,
            (-projVec.y * 0.5f + 0.5f) * height + wy,
            (1.0f + projVec.z) * 0.5f);
    }

    return kexVec3(*this);
}
Exemplo n.º 2
0
void kexCamera::SetupMatrices(void) {
    UpdateAspect();

    // projection
    projMatrix.Identity();
    projMatrix.SetViewProjection(aspect,
        (float)bFixedFOV ? fov : cvarClientFOV.GetFloat(), zNear, zFar);
    
    // scaling the camera object will affect the view projection
    projMatrix.vectors[0].x *= scale.x;
    projMatrix.vectors[1].y *= scale.y;
    
    // model
    modelMatrix.Identity();

    kexQuat yaw(-(angles.yaw + offsetAngle.yaw) + M_PI, kexVec3::vecUp);
    kexQuat pitch(angles.pitch + offsetAngle.pitch, kexVec3::vecRight);
    kexQuat roll(angles.roll + offsetAngle.roll,
        kexVec3(0, kexMath::Sin(angles.pitch), kexMath::Cos(angles.pitch)));

    modelMatrix = kexMatrix((yaw * roll) * pitch);
    rotMatrix = modelMatrix;
    modelMatrix.AddTranslation(-(origin * modelMatrix));

    // frustum
    viewFrustum.MakeClipPlanes(projMatrix, modelMatrix);
    viewFrustum.TransformPoints(origin, angles.ToForwardAxis(), fov, aspect, zNear, zFar);
}
Exemplo n.º 3
0
kexVec3 kexVec3::Cross(const kexVec3 &vec) const {
    return kexVec3(
        vec.z * y - z * vec.y,
        vec.x * z - x * vec.z,
        x * vec.y - vec.x * y
    );
}
Exemplo n.º 4
0
kexVec3 kexVec3::PointAt(kexVec3 &location) const {
    float an1 = (float)atan2(location.x - x, location.y - y);
    float an2 = (float)atan2(location.Distance(*this), location.z - z);

    return kexVec3(
        kexMath::Sin(an1),
        kexMath::Cos(an2),
        kexMath::Cos(an1)
    );
}
Exemplo n.º 5
0
kexVec3 kexLexer::GetVector3(void) {
#ifdef SC_DEBUG
    SC_DebugPrintf("get vector3 (%s)\n", token);
#endif

    float x, y, z;

    ExpectNextToken(TK_LBRACK);
    x = (float)GetFloat();
    y = (float)GetFloat();
    z = (float)GetFloat();
    ExpectNextToken(TK_RBRACK);

    return kexVec3(x, y, z);
}
Exemplo n.º 6
0
kexVec3 kexVec3::operator|(const kexQuat &quat) {
    float xx = quat.x * quat.x;
    float yx = quat.y * quat.x;
    float zx = quat.z * quat.x;
    float wx = quat.w * quat.x;
    float yy = quat.y * quat.y;
    float zy = quat.z * quat.y;
    float wy = quat.w * quat.y;
    float zz = quat.z * quat.z;
    float wz = quat.w * quat.z;
    float ww = quat.w * quat.w;

    return kexVec3(
        ((yx + yx) - (wz + wz)) * y +
        ((wy + wy + zx + zx)) * z +
        (((ww + xx) - yy) - zz) * x,
        ((yy + (ww - xx)) - zz) * y +
        ((zy + zy) - (wx + wx)) * z +
        ((wz + wz) + (yx + yx)) * x,
        ((wx + wx) + (zy + zy)) * y +
        (((ww - xx) - yy) + zz) * z +
        ((zx + zx) - (wy + wy)) * x
    );
}
Exemplo n.º 7
0
kexVec3 kexVec3::operator/(const float val) {
    return kexVec3(x / val, y / val, z / val);
}
Exemplo n.º 8
0
kexVec3 kexVec3::operator/(const kexVec3 &vec) {
    return kexVec3(x / vec.x, y / vec.y, z / vec.z);
}
Exemplo n.º 9
0
kexVec3 kexVec3::operator*(const float val) const {
    return kexVec3(x * val, y * val, z * val);
}
Exemplo n.º 10
0
kexVec3 kexVec3::operator*(const kexVec3 &vec) {
    return kexVec3(x * vec.x, y * vec.y, z * vec.z);
}
Exemplo n.º 11
0
kexVec3 kexVec3::operator-(void) const {
    return kexVec3(-x, -y, -z);
}
Exemplo n.º 12
0
kexVec3 kexVec3::operator+(const float val) {
    return kexVec3(x + val, y + val, z + val);
}
Exemplo n.º 13
0
kexVec3 kexVec3::operator+(kexVec3 &vec) {
    return kexVec3(x + vec.x, y + vec.y, z + vec.z);
}
Exemplo n.º 14
0
kexVec3 kexVec3::operator+(const kexVec3 &vec) const {
    return kexVec3(x + vec.x, y + vec.y, z + vec.z);
}
Exemplo n.º 15
0
kexVec3 kexBBox::Center(void) const {
    return kexVec3(
        (max.x + min.x) * 0.5f,
        (max.y + min.y) * 0.5f,
        (max.z + min.z) * 0.5f);
}
Exemplo n.º 16
0
kexVec3 kexVec3::operator|(const kexMatrix &mtx) {
    return kexVec3(
        mtx.vectors[1].x * y + mtx.vectors[2].x * z + mtx.vectors[0].x * x + mtx.vectors[3].x,
        mtx.vectors[1].y * y + mtx.vectors[2].y * z + mtx.vectors[0].y * x + mtx.vectors[3].y,
        mtx.vectors[1].z * y + mtx.vectors[2].z * z + mtx.vectors[0].z * x + mtx.vectors[3].z);
}
Exemplo n.º 17
0
kexVec3 kexVec3::operator-(const kexVec3 &vec) const {
    return kexVec3(x - vec.x, y - vec.y, z - vec.z);
}
Exemplo n.º 18
0
kexVec3 kexDisplayObject::TransformPoint(const float x, const float y, const float z) {
    return kexVec3(x, y, z) * matrix;
}