2012-01-23 23:45:33 +00:00
|
|
|
#include "camera.h"
|
|
|
|
|
2011-12-10 13:25:22 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
2012-01-24 13:16:20 +00:00
|
|
|
#include "render.h"
|
2012-01-29 11:34:49 +00:00
|
|
|
#include "scenery.h"
|
2012-01-29 17:39:56 +00:00
|
|
|
#include "tools.h"
|
2011-12-10 13:25:22 +00:00
|
|
|
|
2013-04-27 19:41:57 +00:00
|
|
|
struct CameraDefinition
|
|
|
|
{
|
2013-04-27 21:40:31 +00:00
|
|
|
/* Definition */
|
2013-04-27 19:41:57 +00:00
|
|
|
Vector3 location;
|
2013-04-27 21:40:31 +00:00
|
|
|
VectorSpherical direction;
|
2013-04-27 19:41:57 +00:00
|
|
|
double roll;
|
|
|
|
|
2013-04-27 21:40:31 +00:00
|
|
|
/* Projection info */
|
2013-04-27 19:41:57 +00:00
|
|
|
double width;
|
|
|
|
double height;
|
|
|
|
CameraPerspective perspective;
|
|
|
|
|
2013-04-27 21:40:31 +00:00
|
|
|
/* Auto updated */
|
|
|
|
Vector3 target;
|
|
|
|
Vector3 forward;
|
|
|
|
Vector3 right;
|
|
|
|
Vector3 up;
|
2013-04-27 19:41:57 +00:00
|
|
|
Matrix4 project;
|
|
|
|
Matrix4 unproject;
|
|
|
|
};
|
|
|
|
|
2012-04-22 17:12:39 +00:00
|
|
|
void cameraSave(PackStream* stream, CameraDefinition* camera)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2012-04-22 17:12:39 +00:00
|
|
|
v3Save(stream, &camera->location);
|
2013-04-27 21:40:31 +00:00
|
|
|
packWriteDouble(stream, &camera->direction.r);
|
|
|
|
packWriteDouble(stream, &camera->direction.phi);
|
|
|
|
packWriteDouble(stream, &camera->direction.theta);
|
2012-06-17 09:40:40 +00:00
|
|
|
packWriteDouble(stream, &camera->roll);
|
2012-01-23 23:45:33 +00:00
|
|
|
}
|
|
|
|
|
2012-04-22 17:12:39 +00:00
|
|
|
void cameraLoad(PackStream* stream, CameraDefinition* camera)
|
2012-01-23 23:45:33 +00:00
|
|
|
{
|
2012-04-22 17:12:39 +00:00
|
|
|
v3Load(stream, &camera->location);
|
2013-04-27 21:40:31 +00:00
|
|
|
packReadDouble(stream, &camera->direction.r);
|
|
|
|
packReadDouble(stream, &camera->direction.phi);
|
|
|
|
packReadDouble(stream, &camera->direction.theta);
|
2012-06-17 09:40:40 +00:00
|
|
|
packReadDouble(stream, &camera->roll);
|
2011-12-10 13:25:22 +00:00
|
|
|
|
2012-01-29 11:34:49 +00:00
|
|
|
cameraValidateDefinition(camera, 0);
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2013-04-27 19:41:57 +00:00
|
|
|
CameraDefinition* cameraCreateDefinition()
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2013-04-27 19:41:57 +00:00
|
|
|
CameraDefinition* definition;
|
|
|
|
|
|
|
|
definition = malloc(sizeof (CameraDefinition));
|
2012-01-23 23:45:33 +00:00
|
|
|
|
2013-04-27 19:41:57 +00:00
|
|
|
definition->location.x = 0.0;
|
|
|
|
definition->location.y = 0.0;
|
|
|
|
definition->location.z = 0.0;
|
2013-04-27 21:40:31 +00:00
|
|
|
definition->direction.phi = 0.0;
|
|
|
|
definition->direction.theta = 0.0;
|
|
|
|
definition->direction.r = 1.0;
|
2013-04-27 19:41:57 +00:00
|
|
|
definition->roll = 0.0;
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2013-04-27 19:41:57 +00:00
|
|
|
definition->width = 1.0;
|
|
|
|
definition->height = 1.0;
|
2013-04-27 21:40:31 +00:00
|
|
|
definition->perspective.yfov = 1.57;
|
|
|
|
definition->perspective.xratio = 1.0;
|
|
|
|
definition->perspective.znear = 1.0;
|
|
|
|
definition->perspective.zfar = 1000.0;
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2013-04-27 19:41:57 +00:00
|
|
|
cameraValidateDefinition(definition, 0);
|
2012-01-23 23:45:33 +00:00
|
|
|
|
|
|
|
return definition;
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 23:45:33 +00:00
|
|
|
void cameraDeleteDefinition(CameraDefinition* definition)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2013-04-27 19:41:57 +00:00
|
|
|
free(definition);
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 23:45:33 +00:00
|
|
|
void cameraCopyDefinition(CameraDefinition* source, CameraDefinition* destination)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2012-01-23 23:45:33 +00:00
|
|
|
*destination = *source;
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-01-29 11:34:49 +00:00
|
|
|
cameraValidateDefinition(destination, 0);
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2012-01-29 11:34:49 +00:00
|
|
|
void cameraValidateDefinition(CameraDefinition* definition, int check_above)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2013-01-20 15:07:45 +00:00
|
|
|
Renderer* renderer;
|
2012-06-17 09:40:40 +00:00
|
|
|
double water_height, terrain_height, diff;
|
2012-01-29 11:34:49 +00:00
|
|
|
Vector3 move;
|
|
|
|
Matrix4 rotation;
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-01-29 11:34:49 +00:00
|
|
|
if (check_above)
|
|
|
|
{
|
2012-12-09 17:49:28 +00:00
|
|
|
renderer = sceneryCreateStandardRenderer();
|
2013-01-20 15:07:45 +00:00
|
|
|
terrain_height = renderer->terrain->getHeight(renderer, definition->location.x, definition->location.z, 1) + 0.5;
|
2013-02-27 16:38:27 +00:00
|
|
|
water_height = renderer->water->getHeightInfo(renderer).max_height + 0.5;
|
2013-01-20 15:07:45 +00:00
|
|
|
rendererDelete(renderer);
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-01-29 11:34:49 +00:00
|
|
|
if (definition->location.y < water_height || definition->location.y < terrain_height)
|
|
|
|
{
|
|
|
|
if (water_height > terrain_height)
|
|
|
|
{
|
|
|
|
diff = water_height - definition->location.y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
diff = terrain_height - definition->location.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
move.x = move.z = 0.0;
|
|
|
|
move.y = diff;
|
|
|
|
definition->location = v3Add(definition->location, move);
|
|
|
|
}
|
|
|
|
}
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2013-01-16 15:56:17 +00:00
|
|
|
if (definition->location.y > 100.0)
|
|
|
|
{
|
|
|
|
definition->location.y = 100.0;
|
|
|
|
}
|
|
|
|
|
2012-01-29 11:34:49 +00:00
|
|
|
definition->forward.x = 1.0;
|
|
|
|
definition->forward.y = 0.0;
|
|
|
|
definition->forward.z = 0.0;
|
|
|
|
definition->right.x = 0.0;
|
|
|
|
definition->right.y = 0.0;
|
|
|
|
definition->right.z = 1.0;
|
2012-01-23 23:45:33 +00:00
|
|
|
definition->up.x = 0.0;
|
|
|
|
definition->up.y = 1.0;
|
|
|
|
definition->up.z = 0.0;
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2013-04-27 21:40:31 +00:00
|
|
|
rotation = m4NewRotateEuler(definition->direction.phi, definition->direction.theta, definition->roll);
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-01-29 11:34:49 +00:00
|
|
|
definition->forward = m4MultPoint(rotation, definition->forward);
|
|
|
|
definition->right = m4MultPoint(rotation, definition->right);
|
|
|
|
definition->up = m4MultPoint(rotation, definition->up);
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2013-04-27 21:40:31 +00:00
|
|
|
definition->target = v3Add(definition->location, v3FromSpherical(definition->direction));
|
2012-01-29 11:34:49 +00:00
|
|
|
|
2013-04-27 21:40:31 +00:00
|
|
|
definition->project = m4Mult(m4NewPerspective(definition->perspective.yfov, definition->perspective.xratio, definition->perspective.znear, definition->perspective.zfar), m4NewLookAt(definition->location, definition->target, definition->up));
|
2012-01-23 23:45:33 +00:00
|
|
|
definition->unproject = m4Inverse(definition->project);
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2013-04-27 19:41:57 +00:00
|
|
|
Vector3 cameraGetLocation(CameraDefinition* camera)
|
|
|
|
{
|
|
|
|
return camera->location;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 cameraGetTarget(CameraDefinition* camera)
|
|
|
|
{
|
|
|
|
return camera->target;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 cameraGetUpVector(CameraDefinition* camera)
|
|
|
|
{
|
|
|
|
return camera->up;
|
|
|
|
}
|
|
|
|
|
|
|
|
double cameraGetRoll(CameraDefinition* camera)
|
|
|
|
{
|
|
|
|
return camera->roll;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 cameraGetDirection(CameraDefinition* camera)
|
|
|
|
{
|
2013-04-27 21:40:31 +00:00
|
|
|
return v3FromSpherical(camera->direction);
|
2013-04-27 19:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 cameraGetDirectionNormalized(CameraDefinition* camera)
|
2012-01-23 23:45:33 +00:00
|
|
|
{
|
2013-04-27 19:41:57 +00:00
|
|
|
return camera->forward;
|
|
|
|
}
|
|
|
|
|
|
|
|
VectorSpherical cameraGetDirectionSpherical(CameraDefinition* camera)
|
|
|
|
{
|
2013-04-27 21:40:31 +00:00
|
|
|
return camera->direction;
|
2013-04-27 19:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CameraPerspective cameraGetPerspective(CameraDefinition* camera)
|
|
|
|
{
|
|
|
|
return camera->perspective;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cameraSetLocation(CameraDefinition* camera, Vector3 location)
|
|
|
|
{
|
|
|
|
camera->location = location;
|
2012-01-23 23:45:33 +00:00
|
|
|
|
2012-01-29 11:34:49 +00:00
|
|
|
cameraValidateDefinition(camera, 0);
|
2012-01-23 23:45:33 +00:00
|
|
|
}
|
|
|
|
|
2013-04-27 19:41:57 +00:00
|
|
|
void cameraSetLocationCoords(CameraDefinition* camera, double x, double y, double z)
|
2012-01-23 23:45:33 +00:00
|
|
|
{
|
2013-04-27 19:41:57 +00:00
|
|
|
Vector3 v = {x, y, z};
|
|
|
|
cameraSetLocation(camera, v);
|
|
|
|
}
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2013-04-27 19:41:57 +00:00
|
|
|
void cameraSetTarget(CameraDefinition* camera, Vector3 target)
|
|
|
|
{
|
|
|
|
Vector3 forward;
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-01-29 11:34:49 +00:00
|
|
|
forward = v3Sub(target, camera->location);
|
|
|
|
if (v3Norm(forward) < 0.0000001)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2013-04-27 21:40:31 +00:00
|
|
|
camera->direction = v3ToSpherical(forward);
|
2012-01-29 11:34:49 +00:00
|
|
|
|
|
|
|
cameraValidateDefinition(camera, 0);
|
|
|
|
}
|
|
|
|
|
2013-04-27 19:41:57 +00:00
|
|
|
void cameraSetTargetCoords(CameraDefinition* camera, double x, double y, double z)
|
|
|
|
{
|
|
|
|
Vector3 v = {x, y, z};
|
|
|
|
cameraSetTarget(camera, v);
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
void cameraSetRoll(CameraDefinition* camera, double angle)
|
2012-01-29 11:34:49 +00:00
|
|
|
{
|
|
|
|
camera->roll = angle;
|
|
|
|
|
|
|
|
cameraValidateDefinition(camera, 0);
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
2013-04-27 21:40:31 +00:00
|
|
|
void cameraSetZoomToTarget(CameraDefinition* camera, double zoom)
|
|
|
|
{
|
|
|
|
camera->direction.r = zoom;
|
|
|
|
camera->location = v3Add(camera->target, v3Scale(v3FromSpherical(camera->direction), -1.0));
|
|
|
|
|
|
|
|
cameraValidateDefinition(camera, 0);
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
void cameraStrafeForward(CameraDefinition* camera, double value)
|
2012-01-27 16:01:34 +00:00
|
|
|
{
|
2012-01-29 11:34:49 +00:00
|
|
|
camera->location = v3Add(camera->location, v3Scale(camera->forward, value));
|
2012-01-27 16:01:34 +00:00
|
|
|
|
2012-01-29 11:34:49 +00:00
|
|
|
cameraValidateDefinition(camera, 0);
|
2012-01-27 16:01:34 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
void cameraStrafeRight(CameraDefinition* camera, double value)
|
2012-01-27 16:01:34 +00:00
|
|
|
{
|
2012-01-29 11:34:49 +00:00
|
|
|
camera->location = v3Add(camera->location, v3Scale(camera->right, value));
|
2012-01-27 16:01:34 +00:00
|
|
|
|
2012-01-29 11:34:49 +00:00
|
|
|
cameraValidateDefinition(camera, 0);
|
2012-01-27 16:01:34 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
void cameraStrafeUp(CameraDefinition* camera, double value)
|
2012-01-27 16:01:34 +00:00
|
|
|
{
|
2012-01-29 11:34:49 +00:00
|
|
|
camera->location = v3Add(camera->location, v3Scale(camera->up, value));
|
2012-01-27 16:01:34 +00:00
|
|
|
|
2012-01-29 11:34:49 +00:00
|
|
|
cameraValidateDefinition(camera, 0);
|
2012-01-27 16:01:34 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
void cameraRotateYaw(CameraDefinition* camera, double value)
|
2012-01-27 17:21:57 +00:00
|
|
|
{
|
2013-04-27 21:40:31 +00:00
|
|
|
camera->direction.phi += value;
|
2012-01-27 17:21:57 +00:00
|
|
|
|
2012-01-29 11:34:49 +00:00
|
|
|
cameraValidateDefinition(camera, 0);
|
|
|
|
}
|
2012-01-27 17:21:57 +00:00
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
void cameraRotatePitch(CameraDefinition* camera, double value)
|
2012-01-29 11:34:49 +00:00
|
|
|
{
|
2013-04-27 21:40:31 +00:00
|
|
|
camera->direction.theta += value;
|
2012-01-29 11:34:49 +00:00
|
|
|
|
|
|
|
cameraValidateDefinition(camera, 0);
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
void cameraRotateRoll(CameraDefinition* camera, double value)
|
2012-01-29 11:34:49 +00:00
|
|
|
{
|
|
|
|
camera->roll += value;
|
2012-01-27 17:21:57 +00:00
|
|
|
|
2012-01-29 11:34:49 +00:00
|
|
|
cameraValidateDefinition(camera, 0);
|
2012-01-27 17:21:57 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 11:20:52 +00:00
|
|
|
void cameraSetRenderSize(CameraDefinition* camera, int width, int height)
|
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
camera->width = (double)width;
|
|
|
|
camera->height = (double)height;
|
2013-04-27 21:40:31 +00:00
|
|
|
camera->perspective.xratio = camera->width / camera->height;
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-01-31 11:20:52 +00:00
|
|
|
cameraValidateDefinition(camera, 0);
|
|
|
|
}
|
|
|
|
|
2013-04-27 19:41:57 +00:00
|
|
|
Vector3 cameraProject(CameraDefinition* camera, Vector3 point)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2012-01-29 14:23:10 +00:00
|
|
|
point = m4Transform(camera->project, point);
|
2012-06-09 20:26:34 +00:00
|
|
|
if (point.z < 1.0)
|
|
|
|
{
|
|
|
|
point.x = -point.x;
|
|
|
|
point.y = -point.y;
|
|
|
|
}
|
2012-01-31 11:20:52 +00:00
|
|
|
point.x = (point.x + 1.0) * 0.5 * camera->width;
|
|
|
|
point.y = (-point.y + 1.0) * 0.5 * camera->height;
|
2011-12-10 13:25:22 +00:00
|
|
|
return point;
|
|
|
|
}
|
|
|
|
|
2013-04-27 19:41:57 +00:00
|
|
|
Vector3 cameraUnproject(CameraDefinition* camera, Vector3 point)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2012-01-31 11:20:52 +00:00
|
|
|
point.x = (point.x / (0.5 * camera->width) - 1.0);
|
|
|
|
point.y = -(point.y / (0.5 * camera->height) - 1.0);
|
2012-01-29 14:23:10 +00:00
|
|
|
return m4Transform(camera->unproject, point);
|
2011-12-10 13:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render a quad that will fill the view in front of the camera.
|
|
|
|
* This quad can be used for post-processing.
|
2012-01-23 23:45:33 +00:00
|
|
|
*
|
2011-12-10 13:25:22 +00:00
|
|
|
* @param col Color of the polygon.
|
|
|
|
* @param callback Post-processing callback.
|
|
|
|
*/
|
2013-04-27 19:41:57 +00:00
|
|
|
|
2012-01-29 21:45:58 +00:00
|
|
|
/*void cameraPushOverlay(CameraDefinition* camera, Color col, f_RenderFragmentCallback callback)
|
2011-12-10 13:25:22 +00:00
|
|
|
{
|
2012-01-29 21:45:58 +00:00
|
|
|
Vertex v1, v2, v3, v4;
|
2011-12-10 13:25:22 +00:00
|
|
|
Vector3 v;
|
2012-01-23 23:45:33 +00:00
|
|
|
|
2011-12-10 13:25:22 +00:00
|
|
|
v.x = 0.0;
|
|
|
|
v.y = 0.0;
|
|
|
|
v.z = 10.0;
|
2012-01-23 23:45:33 +00:00
|
|
|
v1.location = cameraUnproject(camera, v);
|
2011-12-10 13:25:22 +00:00
|
|
|
v1.color = col;
|
|
|
|
v1.callback = callback;
|
|
|
|
|
|
|
|
v.x = 0.0;
|
2012-06-17 09:40:40 +00:00
|
|
|
v.y = (double)render_height;
|
2011-12-10 13:25:22 +00:00
|
|
|
v.z = 10.0;
|
2012-01-23 23:45:33 +00:00
|
|
|
v2.location = cameraUnproject(camera, v);
|
2011-12-10 13:25:22 +00:00
|
|
|
v2.color = col;
|
|
|
|
v2.callback = callback;
|
2012-01-23 23:45:33 +00:00
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
v.x = (double)render_width;
|
|
|
|
v.y = (double)render_height;
|
2011-12-10 13:25:22 +00:00
|
|
|
v.z = 10.0;
|
2012-01-23 23:45:33 +00:00
|
|
|
v3.location = cameraUnproject(camera, v);
|
2011-12-10 13:25:22 +00:00
|
|
|
v3.color = col;
|
|
|
|
v3.callback = callback;
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
v.x = (double)render_width;
|
2011-12-10 13:25:22 +00:00
|
|
|
v.y = 0.0;
|
|
|
|
v.z = 10.0;
|
2012-01-23 23:45:33 +00:00
|
|
|
v4.location = cameraUnproject(camera, v);
|
2011-12-10 13:25:22 +00:00
|
|
|
v4.color = col;
|
|
|
|
v4.callback = callback;
|
2012-01-23 23:45:33 +00:00
|
|
|
|
2012-01-29 21:45:58 +00:00
|
|
|
renderPushQuad(&v1, &v2, &v3, &v4);
|
|
|
|
}*/
|
2012-05-09 16:26:07 +00:00
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
static inline void _updateBox(Vector3* point, double* xmin, double* xmax, double* ymin, double* ymax, double* zmax)
|
2012-05-09 16:26:07 +00:00
|
|
|
{
|
2012-11-10 17:05:01 +00:00
|
|
|
*xmin = (*xmin < point->x) ? *xmin : point->x;
|
|
|
|
*ymin = (*ymin < point->y) ? *ymin : point->y;
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-11-10 17:05:01 +00:00
|
|
|
*xmax = (*xmax > point->x) ? *xmax : point->x;
|
|
|
|
*ymax = (*ymax > point->y) ? *ymax : point->y;
|
|
|
|
*zmax = (*zmax > point->z) ? *zmax : point->z;
|
2012-05-09 16:26:07 +00:00
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
int cameraIsBoxInView(CameraDefinition* camera, Vector3 center, double xsize, double ysize, double zsize)
|
2012-05-09 16:26:07 +00:00
|
|
|
{
|
|
|
|
Vector3 projected;
|
2012-06-17 09:40:40 +00:00
|
|
|
double xmin, xmax, ymin, ymax, zmax;
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-05-09 16:26:07 +00:00
|
|
|
center.x -= xsize / 2.0;
|
|
|
|
center.y -= ysize / 2.0;
|
|
|
|
center.z -= zsize / 2.0;
|
2013-04-27 19:41:57 +00:00
|
|
|
projected = cameraProject(camera, center);
|
2012-05-09 16:26:07 +00:00
|
|
|
xmin = xmax = projected.x;
|
|
|
|
ymin = ymax = projected.y;
|
|
|
|
zmax = projected.z;
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-05-09 16:26:07 +00:00
|
|
|
center.x += xsize;
|
2013-04-27 19:41:57 +00:00
|
|
|
projected = cameraProject(camera, center);
|
2012-05-09 16:26:07 +00:00
|
|
|
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
|
|
|
|
2012-06-09 20:26:34 +00:00
|
|
|
center.z += zsize;
|
2013-04-27 19:41:57 +00:00
|
|
|
projected = cameraProject(camera, center);
|
2012-05-09 16:26:07 +00:00
|
|
|
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
|
|
|
|
2012-06-09 20:26:34 +00:00
|
|
|
center.x -= xsize;
|
2013-04-27 19:41:57 +00:00
|
|
|
projected = cameraProject(camera, center);
|
2012-05-09 16:26:07 +00:00
|
|
|
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
|
|
|
|
2012-06-09 20:26:34 +00:00
|
|
|
center.y += ysize;
|
2013-04-27 19:41:57 +00:00
|
|
|
projected = cameraProject(camera, center);
|
2012-05-09 16:26:07 +00:00
|
|
|
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2012-06-09 20:26:34 +00:00
|
|
|
center.x += xsize;
|
2013-04-27 19:41:57 +00:00
|
|
|
projected = cameraProject(camera, center);
|
2012-05-09 16:26:07 +00:00
|
|
|
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
|
|
|
|
2012-06-09 20:26:34 +00:00
|
|
|
center.z -= zsize;
|
2013-04-27 19:41:57 +00:00
|
|
|
projected = cameraProject(camera, center);
|
2012-05-09 16:26:07 +00:00
|
|
|
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
|
|
|
|
2012-06-09 20:26:34 +00:00
|
|
|
center.x -= xsize;
|
2013-04-27 19:41:57 +00:00
|
|
|
projected = cameraProject(camera, center);
|
2012-05-09 16:26:07 +00:00
|
|
|
_updateBox(&projected, &xmin, &xmax, &ymin, &ymax, &zmax);
|
2012-12-09 17:49:28 +00:00
|
|
|
|
2013-04-27 21:40:31 +00:00
|
|
|
return xmin <= camera->width && xmax >= 0.0 && ymin <= camera->height && ymax >= 0.0 && zmax >= camera->perspective.znear;
|
2012-05-09 16:26:07 +00:00
|
|
|
}
|
2013-04-27 19:41:57 +00:00
|
|
|
|
|
|
|
int cameraTransitionToAnother(CameraDefinition* current, CameraDefinition* wanted, double factor)
|
|
|
|
{
|
2013-04-27 21:40:31 +00:00
|
|
|
double dx, dy, dz, dr, dphi, dtheta, droll;
|
|
|
|
|
|
|
|
dx = wanted->location.x - current->location.x;
|
|
|
|
dy = wanted->location.y - current->location.y;
|
|
|
|
dz = wanted->location.z - current->location.z;
|
|
|
|
dr = wanted->direction.r - current->direction.r;
|
|
|
|
dphi = wanted->direction.phi - current->direction.phi;
|
|
|
|
dtheta = wanted->direction.theta - current->direction.theta;
|
|
|
|
droll = wanted->roll - current->roll;
|
|
|
|
|
|
|
|
if (fabs(dx) < 0.000001 && fabs(dy) < 0.000001 && fabs(dz) < 0.000001 && fabs(dr) < 0.000001 && fabs(dphi) < 0.000001 && fabs(dtheta) < 0.000001 && fabs(droll) < 0.000001)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
current->location.x += dx * factor;
|
|
|
|
current->location.y += dy * factor;
|
|
|
|
current->location.z += dz * factor;
|
|
|
|
current->direction.r += dr * factor;
|
|
|
|
current->direction.phi += dphi * factor;
|
|
|
|
current->direction.theta += dtheta * factor;
|
|
|
|
current->roll += droll * factor;
|
|
|
|
|
|
|
|
cameraValidateDefinition(current, 0);
|
|
|
|
return 1;
|
|
|
|
}
|
2013-04-27 19:41:57 +00:00
|
|
|
}
|