11 #define CAMERA_HEIGHT 0.5 12 #define CAMERA_NEAR_CLIP 0.2 13 #define CAMERA_FAR_CLIP 8.0 73 void cross(
float& x1,
float& y1,
float& z1,
float x2,
float y2,
float z2 )
77 x3 = y1 * z2 - z1 * y2;
78 y3 = z1 * x2 - x1 * z2;
79 z3 = x1 * y2 - y1 * x2;
89 const std::string& type ) :
90 Model( world, parent, type ),
93 _frame_color_data( NULL ),
94 _valid_vertexbuf_cache( false ),
95 _vertexbuf_cache( NULL ),
98 _camera_quads_size( 0 ),
99 _camera_quads( NULL ),
100 _camera_colors( NULL ),
110 if( world_gui == NULL ) {
111 printf(
"Unable to use Camera Model - it must be run with a GUI world\n" );
119 memset( &geom, 0,
sizeof(geom));
202 glGetIntegerv(GL_VIEWPORT,viewport);
215 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
227 for(
int i = 0; i < buf_size; i++ )
231 glReadPixels(0, 0,
_width, _height,
237 glViewport( viewport[0], viewport[1], viewport[2], viewport[3] );
252 float start_fov = w_fov / 2.0 + 180.0;
253 float start_vert_fov = h_fov / 2.0 + 90.0;
257 float a_space = w_fov / w;
258 float vert_a_space = h_fov / h;
262 for(
int j = 0; j < h; j++ ) {
263 for(
int i = 0; i < w; i++ ) {
265 float a = start_fov -
static_cast< float >( i ) * a_space;
266 float vert_a = start_vert_fov -
static_cast< float >( h - j - 1 ) * vert_a_space;
268 int index = i + j * w;
272 float x = -sin(
dtor( vert_a ) ) * cos(
dtor( a ) );
273 float y = -sin(
dtor( vert_a ) ) * sin(
dtor( a ) );
274 float z = -cos(
dtor( vert_a ) );
278 vertex->
x = x * cos( a ) - y * sin( a );
279 vertex->
y = x * sin( a ) + y * cos( a );
282 x = vertex->
x; y = vertex->
y; z = vertex->
z;
284 vertex->
x = z * sin( a ) + x * cos( a );
286 vertex->
z = z * cos( a ) - x * sin( a );
297 for(
int j = 0; j < h; j++ ) {
298 for(
int i = 0; i < w; i++ ) {
299 int index = i + j * w;
301 const float length = depth_data[ index ];
304 float sx = unit_vertex->
x * length;
305 float sy = unit_vertex->
y * length;
306 float sz = unit_vertex->
z * length;
311 x = 0; y = 0; z = length * M_PI * a_space / 360.0;
312 cross( x, y, z, unit_vertex->
x, unit_vertex->
y, unit_vertex->
z );
314 z = length * M_PI * vert_a_space / 360.0;
317 p[ 0 ] = sx - x; p[ 1 ] = sy - y; p[ 2 ] = sz - z;
318 p[ 3 ] = sx - x; p[ 4 ] = sy - y; p[ 5 ] = sz + z;
319 p[ 6 ] = sx + x; p[ 7 ] = sy + y; p[ 8 ] = sz + z;
320 p[ 9 ] = sx + x; p[ 10 ] = sy + y; p[ 11 ] = sz - z;
325 for(
int i = 0; i < 4; i++ ) {
327 memcpy( cp, color,
sizeof( GLubyte ) * 3 );
333 glEnableClientState( GL_COLOR_ARRAY );
337 glDrawArrays( GL_QUADS, 0, w * h * 4 );
339 glDisableClientState( GL_COLOR_ARRAY );
ModelCamera(World *world, Model *parent, const std::string &type)
static const Stg::Size DEFAULT_SIZE(0.1, 0.07, 0.05)
Canvas * GetCanvas(void) const
The Stage library uses its own namespace.
GLubyte * _frame_color_data
void setDirtyBuffer(void)
virtual void Update()
Capture a new frame ( calls GetFrame )
static const float DEFAULT_VFOV
void cross(float &x1, float &y1, float &z1, float x2, float y2, float z2)
int ReadTuple(const int entity, const char *name, const unsigned int first, const unsigned int num, const char *format,...)
PerspectiveCamera _camera
virtual void DataVisualize(Camera *cam)
Draw Camera Model - TODO.
#define PRINT_DEBUG2(m, a, b)
void setPose(double x, double y, double z)
void setFov(double horiz_fov, double vert_fov)
meters_t z
location in 3 axes
bool _valid_vertexbuf_cache
static const float DEFAULT_HFOV
void RegisterOption(Option *opt)
void setClip(double near, double far)
Pose GetGlobalPose() const
double realDistance(double z_buf_val) const
static Option showCameraData
bool GetFrame()
Take a screenshot from the camera's perspective. return: true for sucess, and data is available via F...
double horizFov(void) const
virtual void SetProjection(void) const
void SetGeom(const Geom &src)
virtual void Draw(void) const
radians_t a
rotation about the z axis.
static const char DEFAULT_GEOM_COLOR[]
void setPitch(double pitch)
double vertFov(void) const
ColoredVertex * _vertexbuf_cache