Esempio n. 1
0
    Camera::Camera(const vec3& position, const vec3& rot, float fov) :
        m_Position(position), m_Rotation(rot), m_Fov(fov)
    {
        auto x = -((float)FRAME_WIDTH / (float)FRAME_HEIGHT);
        auto y = 1.f;

        vec3 corner(x, y, 1);
        vec3 center(0, 0, 1);

        auto scaling = tan(radians(m_Fov * 0.5f)) / (corner - center).length();

        x *= scaling;
        y *= scaling;

        m_RotationMatrix = CreateRotationMatrix(m_Rotation);
        m_TopLeft = vec3(m_RotationMatrix * vec4(x, y, 1, 1));
        m_TopRight = vec3(m_RotationMatrix * vec4(-x, y, 1, 1));
        m_DownLeft = vec3(m_RotationMatrix * vec4(x, -y, 1, 1));

        m_UpDir = vec3(m_RotationMatrix * vec4(0, 1, 0, 1));
        m_RightDir = vec3(m_RotationMatrix * vec4(1, 0, 0, 1));
        m_FrontDir = vec3(m_RotationMatrix * vec4(0, 0, 1, 1));

        m_TopLeft += m_Position;
        m_TopRight += m_Position;
        m_DownLeft += m_Position;
    }
Esempio n. 2
0
//===========================================================================
//
// Parameter:				-
// Returns:					-
// Changes Globals:		-
//===========================================================================
int AAS_TransformPlane(int planenum, vec3_t origin, vec3_t angles)
{
	float newdist, matrix[3][3];
	vec3_t normal;

	//rotate the node plane
	VectorCopy(mapplanes[planenum].normal, normal);
	CreateRotationMatrix(angles, matrix);
	RotatePoint(normal, matrix);
	newdist = mapplanes[planenum].dist + DotProduct(normal, origin);
	return FindFloatPlane(normal, newdist);
} //end of the function AAS_TransformPlane
Esempio n. 3
0
/*
==================
CM_TransformedBoxTrace

Handles offseting and rotation of the end points for moving and
rotating entities
==================
*/
void CM_TransformedBoxTrace(trace_t *results, const vec3_t start, const vec3_t end,
                            const vec3_t mins, const vec3_t maxs,
                            clipHandle_t model, int brushmask,
                            const vec3_t origin, const vec3_t angles, int capsule)
{
	trace_t  trace;
	vec3_t   start_l, end_l;
	qboolean rotated;
	vec3_t   offset;
	vec3_t   symetricSize[2];
	vec3_t   matrix[3], transpose[3];
	int      i;
	float    halfwidth;
	float    halfheight;
	float    t;
	sphere_t sphere;

	if (!mins)
	{
		mins = vec3_origin;
	}
	if (!maxs)
	{
		maxs = vec3_origin;
	}

	// adjust so that mins and maxs are always symetric, which
	// avoids some complications with plane expanding of rotated bmodels
	for (i = 0 ; i < 3 ; i++)
	{
		offset[i]          = (mins[i] + maxs[i]) * 0.5;
		symetricSize[0][i] = mins[i] - offset[i];
		symetricSize[1][i] = maxs[i] - offset[i];
		start_l[i]         = start[i] + offset[i];
		end_l[i]           = end[i] + offset[i];
	}

	// subtract origin offset
	VectorSubtract(start_l, origin, start_l);
	VectorSubtract(end_l, origin, end_l);

	// rotate start and end into the models frame of reference
	if (model != BOX_MODEL_HANDLE &&
	    (angles[0] || angles[1] || angles[2]))
	{
		rotated = qtrue;
	}
	else
	{
		rotated = qfalse;
	}

	halfwidth  = symetricSize[1][0];
	halfheight = symetricSize[1][2];

	sphere.use        = capsule;
	sphere.radius     = (halfwidth > halfheight) ? halfheight : halfwidth;
	sphere.halfheight = halfheight;
	t                 = halfheight - sphere.radius;

	if (rotated)
	{
		// rotation on trace line (start-end) instead of rotating the bmodel
		// NOTE: This is still incorrect for bounding boxes because the actual bounding
		//       box that is swept through the model is not rotated. We cannot rotate
		//       the bounding box or the bmodel because that would make all the brush
		//       bevels invalid.
		//       However this is correct for capsules since a capsule itself is rotated too.
		CreateRotationMatrix(angles, matrix);
		RotatePoint(start_l, matrix);
		RotatePoint(end_l, matrix);
		// rotated sphere offset for capsule
		sphere.offset[0] = matrix[0][2] * t;
		sphere.offset[1] = -matrix[1][2] * t;
		sphere.offset[2] = matrix[2][2] * t;
	}
	else
	{
		VectorSet(sphere.offset, 0, 0, t);
	}

	// sweep the box through the model
	CM_Trace(&trace, start_l, end_l, symetricSize[0], symetricSize[1], model, origin, brushmask, capsule, &sphere);

	// if the bmodel was rotated and there was a collision
	if (rotated && trace.fraction != 1.0)
	{
		// rotation of bmodel collision plane
		TransposeMatrix(matrix, transpose);
		RotatePoint(trace.plane.normal, transpose);
	}

	// re-calculate the end position of the trace because the trace.endpos
	// calculated by CM_Trace could be rotated and have an offset
	trace.endpos[0] = start[0] + trace.fraction * (end[0] - start[0]);
	trace.endpos[1] = start[1] + trace.fraction * (end[1] - start[1]);
	trace.endpos[2] = start[2] + trace.fraction * (end[2] - start[2]);

	*results = trace;
}