diff options
Diffstat (limited to 'intern')
26 files changed, 282 insertions, 146 deletions
diff --git a/intern/container/CTR_UHeap.h b/intern/container/CTR_UHeap.h index ad3d7d2bb02..8711d4375cb 100644 --- a/intern/container/CTR_UHeap.h +++ b/intern/container/CTR_UHeap.h @@ -56,7 +56,7 @@ class CTR_UHeapable { public : int & HeapPos( - ){ + ) { return m_ind; }; float & @@ -93,7 +93,7 @@ protected : }; ~CTR_UHeapable( - ){ + ) { }; }; @@ -214,7 +214,7 @@ private: HeapType *base, int i, int j - ){ + ) { std::swap(m_vector[i],m_vector[j]); CTR_UHeapable *heap_i = base + m_vector[i]; diff --git a/intern/cycles/blender/blender_camera.cpp b/intern/cycles/blender/blender_camera.cpp index bdd02bb5086..9bc82344fcc 100644 --- a/intern/cycles/blender/blender_camera.cpp +++ b/intern/cycles/blender/blender_camera.cpp @@ -56,6 +56,11 @@ struct BlenderCamera { float sensor_width; float sensor_height; + float border_left; + float border_right; + float border_bottom; + float border_top; + Transform matrix; }; @@ -70,6 +75,8 @@ static void blender_camera_init(BlenderCamera *bcam) bcam->sensor_height = 18.0f; bcam->sensor_fit = BlenderCamera::AUTO; bcam->shuttertime = 1.0f; + bcam->border_right = 1.0f; + bcam->border_top = 1.0f; } static float blender_camera_focal_distance(BL::Object b_ob, BL::Camera b_camera) @@ -188,85 +195,94 @@ static Transform blender_camera_matrix(const Transform& tfm, CameraType type) return transform_clear_scale(result); } -static void blender_camera_sync(Camera *cam, BlenderCamera *bcam, int width, int height) +static void blender_camera_viewplane(BlenderCamera *bcam, int width, int height, + float *left, float *right, float *bottom, float *top, float *aspectratio, float *sensor_size) { - /* copy camera to compare later */ - Camera prevcam = *cam; - /* dimensions */ float xratio = width*bcam->pixelaspect.x; float yratio = height*bcam->pixelaspect.y; /* compute x/y aspect and ratio */ - float aspectratio, xaspect, yaspect; + float xaspect, yaspect; /* sensor fitting */ bool horizontal_fit; - float sensor_size; - - cam->sensorwidth = bcam->sensor_width; - cam->sensorheight = bcam->sensor_height; if(bcam->sensor_fit == BlenderCamera::AUTO) { horizontal_fit = (xratio > yratio); - sensor_size = bcam->sensor_width; + *sensor_size = bcam->sensor_width; } else if(bcam->sensor_fit == BlenderCamera::HORIZONTAL) { horizontal_fit = true; - sensor_size = bcam->sensor_width; + *sensor_size = bcam->sensor_width; } else { horizontal_fit = false; - sensor_size = bcam->sensor_height; + *sensor_size = bcam->sensor_height; } if(horizontal_fit) { - aspectratio= xratio/yratio; - xaspect= aspectratio; + *aspectratio= xratio/yratio; + xaspect= *aspectratio; yaspect= 1.0f; } else { - aspectratio= yratio/xratio; + *aspectratio= yratio/xratio; xaspect= 1.0f; - yaspect= aspectratio; + yaspect= *aspectratio; } /* modify aspect for orthographic scale */ if(bcam->type == CAMERA_ORTHOGRAPHIC) { - xaspect = xaspect*bcam->ortho_scale/(aspectratio*2.0f); - yaspect = yaspect*bcam->ortho_scale/(aspectratio*2.0f); - aspectratio = bcam->ortho_scale/2.0f; + xaspect = xaspect*bcam->ortho_scale/(*aspectratio*2.0f); + yaspect = yaspect*bcam->ortho_scale/(*aspectratio*2.0f); + *aspectratio = bcam->ortho_scale/2.0f; } if(bcam->type == CAMERA_PANORAMA) { /* set viewplane */ - cam->left = 0.0f; - cam->right = 1.0f; - cam->bottom = 0.0f; - cam->top = 1.0f; + *left = 0.0f; + *right = 1.0f; + *bottom = 0.0f; + *top = 1.0f; } else { /* set viewplane */ - cam->left = -xaspect; - cam->right = xaspect; - cam->bottom = -yaspect; - cam->top = yaspect; + *left = -xaspect; + *right = xaspect; + *bottom = -yaspect; + *top = yaspect; /* zoom for 3d camera view */ - cam->left *= bcam->zoom; - cam->right *= bcam->zoom; - cam->bottom *= bcam->zoom; - cam->top *= bcam->zoom; + *left *= bcam->zoom; + *right *= bcam->zoom; + *bottom *= bcam->zoom; + *top *= bcam->zoom; /* modify viewplane with camera shift and 3d camera view offset */ - float dx = 2.0f*(aspectratio*bcam->shift.x + bcam->offset.x*xaspect*2.0f); - float dy = 2.0f*(aspectratio*bcam->shift.y + bcam->offset.y*yaspect*2.0f); + float dx = 2.0f*(*aspectratio*bcam->shift.x + bcam->offset.x*xaspect*2.0f); + float dy = 2.0f*(*aspectratio*bcam->shift.y + bcam->offset.y*yaspect*2.0f); - cam->left += dx; - cam->right += dx; - cam->bottom += dy; - cam->top += dy; + *left += dx; + *right += dx; + *bottom += dy; + *top += dy; } +} + +static void blender_camera_sync(Camera *cam, BlenderCamera *bcam, int width, int height) +{ + /* copy camera to compare later */ + Camera prevcam = *cam; + float aspectratio, sensor_size; + + /* viewplane */ + blender_camera_viewplane(bcam, width, height, + &cam->left, &cam->right, &cam->bottom, &cam->top, &aspectratio, &sensor_size); + + /* sensor */ + cam->sensorwidth = bcam->sensor_width; + cam->sensorheight = bcam->sensor_height; /* clipping distances */ cam->nearclip = bcam->nearclip; @@ -294,6 +310,12 @@ static void blender_camera_sync(Camera *cam, BlenderCamera *bcam, int width, int cam->use_motion = false; cam->shuttertime = bcam->shuttertime; + /* border */ + cam->border_left = bcam->border_left; + cam->border_right = bcam->border_right; + cam->border_bottom = bcam->border_bottom; + cam->border_top = bcam->border_top; + /* set update flag */ if(cam->modified(prevcam)) cam->tag_update(); @@ -313,6 +335,14 @@ void BlenderSync::sync_camera(BL::Object b_override, int width, int height) bcam.pixelaspect.y = r.pixel_aspect_y(); bcam.shuttertime = r.motion_blur_shutter(); + /* border */ + if(r.use_border()) { + bcam.border_left = r.border_min_x(); + bcam.border_right = r.border_max_x(); + bcam.border_bottom = r.border_min_y(); + bcam.border_top = r.border_max_y(); + } + /* camera object */ BL::Object b_ob = b_scene.camera(); @@ -348,67 +378,142 @@ void BlenderSync::sync_camera_motion(BL::Object b_ob, int motion) /* Sync 3D View Camera */ -void BlenderSync::sync_view(BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, int width, int height) +static void blender_camera_from_view(BlenderCamera *bcam, BL::Scene b_scene, BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, int width, int height) { - BlenderCamera bcam; - blender_camera_init(&bcam); - /* 3d view parameters */ - bcam.nearclip = b_v3d.clip_start(); - bcam.farclip = b_v3d.clip_end(); - bcam.lens = b_v3d.lens(); - bcam.shuttertime = b_scene.render().motion_blur_shutter(); + bcam->nearclip = b_v3d.clip_start(); + bcam->farclip = b_v3d.clip_end(); + bcam->lens = b_v3d.lens(); + bcam->shuttertime = b_scene.render().motion_blur_shutter(); if(b_rv3d.view_perspective() == BL::RegionView3D::view_perspective_CAMERA) { /* camera view */ BL::Object b_ob = (b_v3d.lock_camera_and_layers())? b_scene.camera(): b_v3d.camera(); if(b_ob) { - blender_camera_from_object(&bcam, b_ob); + blender_camera_from_object(bcam, b_ob); /* magic zoom formula */ - bcam.zoom = (float)b_rv3d.view_camera_zoom(); - bcam.zoom = (1.41421f + bcam.zoom/50.0f); - bcam.zoom *= bcam.zoom; - bcam.zoom = 2.0f/bcam.zoom; + bcam->zoom = (float)b_rv3d.view_camera_zoom(); + bcam->zoom = (1.41421f + bcam->zoom/50.0f); + bcam->zoom *= bcam->zoom; + bcam->zoom = 2.0f/bcam->zoom; /* offset */ - bcam.offset = get_float2(b_rv3d.view_camera_offset()); + bcam->offset = get_float2(b_rv3d.view_camera_offset()); } } else if(b_rv3d.view_perspective() == BL::RegionView3D::view_perspective_ORTHO) { /* orthographic view */ - bcam.farclip *= 0.5; - bcam.nearclip = -bcam.farclip; + bcam->farclip *= 0.5; + bcam->nearclip = -bcam->farclip; - bcam.type = CAMERA_ORTHOGRAPHIC; - bcam.ortho_scale = b_rv3d.view_distance(); + bcam->type = CAMERA_ORTHOGRAPHIC; + bcam->ortho_scale = b_rv3d.view_distance(); } - bcam.zoom *= 2.0f; + bcam->zoom *= 2.0f; /* 3d view transform */ - bcam.matrix = transform_inverse(get_transform(b_rv3d.view_matrix())); + bcam->matrix = transform_inverse(get_transform(b_rv3d.view_matrix())); +} + +static void blender_camera_border(BlenderCamera *bcam, BL::Scene b_scene, BL::SpaceView3D b_v3d, + BL::RegionView3D b_rv3d, int width, int height) +{ + BL::RenderSettings r = b_scene.render(); + + if(!r.use_border()) + return; + + /* camera view? */ + if(!(b_rv3d && b_rv3d.view_perspective() == BL::RegionView3D::view_perspective_CAMERA)) + return; + + BL::Object b_ob = (b_v3d.lock_camera_and_layers())? b_scene.camera(): b_v3d.camera(); + + if(!b_ob) + return; + + bcam->border_left = r.border_min_x(); + bcam->border_right = r.border_max_x(); + bcam->border_bottom = r.border_min_y(); + bcam->border_top = r.border_max_y(); + + float cam_left, cam_right, cam_bottom, cam_top; + float view_left, view_right, view_bottom, view_top; + float view_aspect, cam_aspect, sensor_size; + + /* get viewport viewplane */ + BlenderCamera view_bcam; + blender_camera_init(&view_bcam); + blender_camera_from_view(&view_bcam, b_scene, b_v3d, b_rv3d, width, height); + + blender_camera_viewplane(&view_bcam, width, height, + &view_left, &view_right, &view_bottom, &view_top, &view_aspect, &sensor_size); + + view_left /= view_aspect; + view_right /= view_aspect; + view_bottom /= view_aspect; + view_top /= view_aspect; + + /* get camera viewplane */ + BlenderCamera cam_bcam; + blender_camera_init(&cam_bcam); + blender_camera_from_object(&cam_bcam, b_ob); + + width = (int)(r.resolution_x()*r.resolution_percentage()/100); + height = (int)(r.resolution_y()*r.resolution_percentage()/100); + + blender_camera_viewplane(&cam_bcam, width, height, + &cam_left, &cam_right, &cam_bottom, &cam_top, &cam_aspect, &sensor_size); + + cam_left /= cam_aspect; + cam_right /= cam_aspect; + cam_bottom /= cam_aspect; + cam_top /= cam_aspect; + + /* determine viewport subset matching camera border */ + float tmp_left = ((cam_left - view_left) / (view_right - view_left)); + float tmp_right = ((cam_right - view_left) / (view_right - view_left)); + float tmp_bottom = ((cam_bottom - view_bottom) / (view_top - view_bottom)); + float tmp_top = ((cam_top - view_bottom) / (view_top - view_bottom)); + + bcam->border_left = tmp_left + bcam->border_left*(tmp_right - tmp_left); + bcam->border_right = tmp_left + bcam->border_right*(tmp_right - tmp_left); + bcam->border_bottom = tmp_bottom + bcam->border_bottom*(tmp_top - tmp_bottom); + bcam->border_top = tmp_bottom + bcam->border_top*(tmp_top - tmp_bottom); + + /* clamp */ + bcam->border_left = max(bcam->border_left, 0.0f); + bcam->border_right = min(bcam->border_right, 1.0f); + bcam->border_bottom = max(bcam->border_bottom, 0.0f); + bcam->border_top = min(bcam->border_top, 1.0f); +} + +void BlenderSync::sync_view(BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, int width, int height) +{ + BlenderCamera bcam; + blender_camera_init(&bcam); + blender_camera_from_view(&bcam, b_scene, b_v3d, b_rv3d, width, height); + blender_camera_border(&bcam, b_scene, b_v3d, b_rv3d, width, height); - /* sync */ blender_camera_sync(scene->camera, &bcam, width, height); } -BufferParams BlenderSync::get_buffer_params(BL::Scene b_scene, BL::RegionView3D b_rv3d, int width, int height) +BufferParams BlenderSync::get_buffer_params(BL::Scene b_scene, Camera *cam, int width, int height) { BufferParams params; params.full_width = width; params.full_height = height; - /* border render */ - BL::RenderSettings r = b_scene.render(); - - if(!b_rv3d && r.use_border()) { - params.full_x = r.border_min_x()*width; - params.full_y = r.border_min_y()*height; - params.width = (int)(r.border_max_x()*width) - params.full_x; - params.height = (int)(r.border_max_y()*height) - params.full_y; + if(b_scene.render().use_border()) { + /* border render */ + params.full_x = cam->border_left*width; + params.full_y = cam->border_bottom*height; + params.width = (int)(cam->border_right*width) - params.full_x; + params.height = (int)(cam->border_top*height) - params.full_y; } else { params.width = width; diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp index 997909f1b92..9726f7b94cf 100644 --- a/intern/cycles/blender/blender_session.cpp +++ b/intern/cycles/blender/blender_session.cpp @@ -106,7 +106,7 @@ void BlenderSession::create_session() session->set_pause(BlenderSync::get_session_pause(b_scene, background)); /* set buffer parameters */ - BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, b_rv3d, width, height); + BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, scene->camera, width, height); session->reset(buffer_params, session_params.samples); } @@ -181,7 +181,7 @@ void BlenderSession::render() { /* get buffer parameters */ SessionParams session_params = BlenderSync::get_session_params(b_userpref, b_scene, background); - BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, b_rv3d, width, height); + BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, scene->camera, width, height); int w = buffer_params.width, h = buffer_params.height; /* create render result */ @@ -326,7 +326,7 @@ void BlenderSession::synchronize() /* reset if needed */ if(scene->need_reset()) { - BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, b_rv3d, width, height); + BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, scene->camera, width, height); session->reset(buffer_params, session_params.samples); } } @@ -364,7 +364,7 @@ bool BlenderSession::draw(int w, int h) /* reset if requested */ if(reset) { SessionParams session_params = BlenderSync::get_session_params(b_userpref, b_scene, background); - BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, b_rv3d, width, height); + BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, scene->camera, w, h); session->reset(buffer_params, session_params.samples); } @@ -374,7 +374,7 @@ bool BlenderSession::draw(int w, int h) update_status_progress(); /* draw */ - BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, b_rv3d, width, height); + BufferParams buffer_params = BlenderSync::get_buffer_params(b_scene, scene->camera, width, height); return !session->draw(buffer_params); } diff --git a/intern/cycles/blender/blender_sync.h b/intern/cycles/blender/blender_sync.h index 10afd468850..bc6258d35ac 100644 --- a/intern/cycles/blender/blender_sync.h +++ b/intern/cycles/blender/blender_sync.h @@ -63,7 +63,7 @@ public: static SceneParams get_scene_params(BL::Scene b_scene, bool background); static SessionParams get_session_params(BL::UserPreferences b_userpref, BL::Scene b_scene, bool background); static bool get_session_pause(BL::Scene b_scene, bool background); - static BufferParams get_buffer_params(BL::Scene b_scene, BL::RegionView3D b_rv3d, int width, int height); + static BufferParams get_buffer_params(BL::Scene b_scene, Camera *cam, int width, int height); private: /* sync */ diff --git a/intern/cycles/kernel/kernel_light.h b/intern/cycles/kernel/kernel_light.h index a056cd71bb1..2bc5a882ce5 100644 --- a/intern/cycles/kernel/kernel_light.h +++ b/intern/cycles/kernel/kernel_light.h @@ -391,6 +391,10 @@ __device float light_sample_pdf(KernelGlobals *kg, LightSample *ls, float3 I, fl __device void light_select(KernelGlobals *kg, int index, float randu, float randv, float3 P, LightSample *ls, float *pdf) { regular_light_sample(kg, index, randu, randv, P, ls, pdf); + + /* compute incoming direction and distance */ + if(ls->t != FLT_MAX) + ls->D = normalize_len(ls->P - P, &ls->t); } __device float light_select_pdf(KernelGlobals *kg, LightSample *ls, float3 I, float t) diff --git a/intern/cycles/kernel/kernel_path.h b/intern/cycles/kernel/kernel_path.h index e0e17ee57dc..e41a5a62c14 100644 --- a/intern/cycles/kernel/kernel_path.h +++ b/intern/cycles/kernel/kernel_path.h @@ -365,7 +365,7 @@ __device float4 kernel_path_integrate(KernelGlobals *kg, RNG *rng, int sample, R #ifdef __MULTI_LIGHT__ /* index -1 means randomly sample from distribution */ - int i = (kernel_data.integrator.num_distribution)? -1: 0; + int i = (kernel_data.integrator.num_all_lights)? 0: -1; for(; i < kernel_data.integrator.num_all_lights; i++) { #else diff --git a/intern/cycles/render/buffers.cpp b/intern/cycles/render/buffers.cpp index a80851b945a..a7fd47c94cf 100644 --- a/intern/cycles/render/buffers.cpp +++ b/intern/cycles/render/buffers.cpp @@ -311,8 +311,14 @@ void DisplayBuffer::draw_set(int width, int height) void DisplayBuffer::draw(Device *device) { - if(draw_width != 0 && draw_height != 0) + if(draw_width != 0 && draw_height != 0) { + glPushMatrix(); + glTranslatef(params.full_x, params.full_y, 0.0f); + device->draw_pixels(rgba, 0, draw_width, draw_height, 0, params.width, params.height, transparent); + + glPopMatrix(); + } } bool DisplayBuffer::draw_ready() diff --git a/intern/cycles/render/camera.cpp b/intern/cycles/render/camera.cpp index 3ecffab7cbc..ed239074cd4 100644 --- a/intern/cycles/render/camera.cpp +++ b/intern/cycles/render/camera.cpp @@ -58,6 +58,11 @@ Camera::Camera() bottom = -1.0f; top = 1.0f; + border_left = 0.0f; + border_right = 1.0f; + border_bottom = 0.0f; + border_top = 1.0f; + screentoworld = transform_identity(); rastertoworld = transform_identity(); ndctoworld = transform_identity(); @@ -248,6 +253,10 @@ bool Camera::modified(const Camera& cam) (right == cam.right) && (bottom == cam.bottom) && (top == cam.top) && + (border_left == cam.border_left) && + (border_right == cam.border_right) && + (border_bottom == cam.border_bottom) && + (border_top == cam.border_top) && (matrix == cam.matrix) && (motion == cam.motion) && (use_motion == cam.use_motion) && diff --git a/intern/cycles/render/camera.h b/intern/cycles/render/camera.h index 7a09b5981e4..647423d88ba 100644 --- a/intern/cycles/render/camera.h +++ b/intern/cycles/render/camera.h @@ -67,6 +67,9 @@ public: int width, height; float left, right, bottom, top; + /* border */ + float border_left, border_right, border_bottom, border_top; + /* transformation */ Transform matrix; diff --git a/intern/cycles/render/session.cpp b/intern/cycles/render/session.cpp index 34a0c0ff877..173d73ea2c7 100644 --- a/intern/cycles/render/session.cpp +++ b/intern/cycles/render/session.cpp @@ -27,6 +27,7 @@ #include "util_foreach.h" #include "util_function.h" +#include "util_opengl.h" #include "util_task.h" #include "util_time.h" diff --git a/intern/cycles/util/util_system.cpp b/intern/cycles/util/util_system.cpp index e8c81e57654..ad7f3347cee 100644 --- a/intern/cycles/util/util_system.cpp +++ b/intern/cycles/util/util_system.cpp @@ -152,7 +152,7 @@ bool system_cpu_support_optimized() /*__cpuid(result, 0x80000000); num_ex = result[0];*/ - if(num >= 1){ + if(num >= 1) { __cpuid(result, 0x00000001); caps.mmx = (result[3] & ((int)1 << 23)) != 0; caps.sse = (result[3] & ((int)1 << 25)) != 0; @@ -167,7 +167,7 @@ bool system_cpu_support_optimized() caps.fma3 = (result[2] & ((int)1 << 12)) != 0; } - /*if(num_ex >= 0x80000001){ + /*if(num_ex >= 0x80000001) { __cpuid(result, 0x80000001); caps.x64 = (result[3] & ((int)1 << 29)) != 0; caps.sse4a = (result[2] & ((int)1 << 6)) != 0; diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h index 7614cb80e00..8454f338645 100644 --- a/intern/ghost/GHOST_Types.h +++ b/intern/ghost/GHOST_Types.h @@ -56,8 +56,7 @@ typedef unsigned long long GHOST_TUns64; typedef void *GHOST_TUserDataPtr; -typedef enum -{ +typedef enum { GHOST_kFailure = 0, GHOST_kSuccess } GHOST_TSuccess; diff --git a/intern/itasc/Armature.cpp b/intern/itasc/Armature.cpp index dd5c1921a98..1dacb8bc184 100644 --- a/intern/itasc/Armature.cpp +++ b/intern/itasc/Armature.cpp @@ -158,7 +158,7 @@ void Armature::pushQ(CacheTS timestamp) { if (m_qCCh >= 0) { // try to keep the cache if the joints are the same - m_cache->addCacheVectorIfDifferent(this, m_qCCh, timestamp, &m_qKdl(0), m_qKdl.rows(), KDL::epsilon); + m_cache->addCacheVectorIfDifferent(this, m_qCCh, timestamp, m_qKdl(0), m_qKdl.rows(), KDL::epsilon); m_qCTs = timestamp; } } @@ -170,8 +170,8 @@ bool Armature::popQ(CacheTS timestamp) double* item; item = (double*)m_cache->getPreviousCacheItem(this, m_qCCh, ×tamp); if (item && m_qCTs != timestamp) { - double& q = m_qKdl(0); - memcpy(&q, item, m_qKdl.rows()*sizeof(q)); + double* q = m_qKdl(0); + memcpy(q, item, m_qKdl.rows()*sizeof(double)); m_qCTs = timestamp; // changing the joint => recompute the jacobian updateJacobian(); @@ -255,7 +255,7 @@ bool Armature::getSegment(const std::string& name, const unsigned int q_size, co p_tip = &sit->second.segment.getFrameToTip(); for (unsigned int dof=0; dof<p_joint->getNDof(); dof++) { (&q_rest)[dof] = m_joints[sit->second.q_nr+dof].rest; - (&q)[dof] = m_qKdl(sit->second.q_nr+dof); + (&q)[dof] = m_qKdl[sit->second.q_nr+dof]; } return true; } @@ -267,7 +267,7 @@ double Armature::getMaxJointChange() double maxJoint = 0.0; for (unsigned int i=0; i<m_njoint; i++) { // this is a very rough calculation, it doesn't work well for spherical joint - double joint = fabs(m_oldqKdl(i)-m_qKdl(i)); + double joint = fabs(m_oldqKdl[i]-m_qKdl[i]); if (maxJoint < joint) maxJoint = joint; } @@ -392,7 +392,7 @@ bool Armature::finalize() m_newqKdl.resize(m_njoint); m_qdotKdl.resize(m_njoint); for (i=0; i<m_njoint; i++) { - m_newqKdl(i) = m_oldqKdl(i) = m_qKdl(i) = m_joints[i].rest; + m_newqKdl[i] = m_oldqKdl[i] = m_qKdl[i] = m_joints[i].rest; } updateJacobian(); // estimate the maximum size of the robot arms @@ -447,15 +447,15 @@ bool Armature::updateJoint(const Timestamp& timestamp, JointLockCallback& callba // integration and joint limit // for spherical joint we must use a more sophisticated method unsigned int q_nr; - double* qdot=&m_qdotKdl(0); - double* q=&m_qKdl(0); - double* newq=&m_newqKdl(0); + double* qdot=m_qdotKdl(0); + double* q=m_qKdl(0); + double* newq=m_newqKdl(0); double norm, qx, qz, CX, CZ, sx, sz; bool locked = false; int unlocked = 0; for (q_nr=0; q_nr<m_nq; ++q_nr) - m_qdotKdl(q_nr)=m_qdot(q_nr); + qdot[q_nr]=m_qdot[q_nr]; for (q_nr=0; q_nr<m_nq; ) { Joint_struct* joint = &m_joints[q_nr]; @@ -624,7 +624,7 @@ void Armature::updateKinematics(const Timestamp& timestamp){ return; // the new joint value have been computed already, just copy - memcpy(&m_qKdl(0), &m_newqKdl(0), sizeof(double)*m_qKdl.rows()); + memcpy(m_qKdl(0), m_newqKdl(0), sizeof(double)*m_qKdl.rows()); pushCache(timestamp); updateJacobian(); // here update the desired output. @@ -677,7 +677,7 @@ void Armature::updateControlOutput(const Timestamp& timestamp) if (!timestamp.substep) { // save previous joint state for getMaxJointChange() - memcpy(&m_oldqKdl(0), &m_qKdl(0), sizeof(double)*m_qKdl.rows()); + memcpy(m_oldqKdl(0), m_qKdl(0), sizeof(double)*m_qKdl.rows()); for (unsigned int i=0; i<m_neffector; i++) { m_effectors[i].oldpose = m_effectors[i].pose; } @@ -696,8 +696,8 @@ void Armature::updateControlOutput(const Timestamp& timestamp) JointConstraint_struct* pConstraint = *it; unsigned int nr, i; for (i=0, nr = pConstraint->segment->second.q_nr; i<pConstraint->v_nr; i++, nr++) { - *(double*)&pConstraint->value[i].y = m_qKdl(nr); - *(double*)&pConstraint->value[i].ydot = m_qdotKdl(nr); + *(double*)&pConstraint->value[i].y = m_qKdl[nr]; + *(double*)&pConstraint->value[i].ydot = m_qdotKdl[nr]; } if (pConstraint->function && (pConstraint->substep || (!timestamp.reiterate && !timestamp.substep))) { (*pConstraint->function)(timestamp, pConstraint->values, pConstraint->v_nr, pConstraint->param); diff --git a/intern/itasc/CMakeLists.txt b/intern/itasc/CMakeLists.txt index 3d24a0cb8c6..f4bc0326ea1 100644 --- a/intern/itasc/CMakeLists.txt +++ b/intern/itasc/CMakeLists.txt @@ -318,8 +318,5 @@ set(SRC ../../extern/Eigen3/Eigen/src/Cholesky/LLT.h ) -if(WIN32) - add_definitions(-DEIGEN_DONT_ALIGN_STATICALLY) -endif() blender_add_lib(bf_intern_itasc "${SRC}" "${INC}" "${INC_SYS}") diff --git a/intern/itasc/Distance.cpp b/intern/itasc/Distance.cpp index 7cf04367a4e..c9efca101e3 100644 --- a/intern/itasc/Distance.cpp +++ b/intern/itasc/Distance.cpp @@ -189,7 +189,7 @@ void Distance::updateKinematics(const Timestamp& timestamp) void Distance::updateJacobian() { for(unsigned int i=0;i<6;i++) - m_chiKdl(i)=m_chi(i); + m_chiKdl[i]=m_chi[i]; m_fksolver->JntToCart(m_chiKdl,m_internalPose); m_jacsolver->JntToJac(m_chiKdl,m_jac); diff --git a/intern/itasc/SConscript b/intern/itasc/SConscript index 69dddf40228..c1ad931c665 100644 --- a/intern/itasc/SConscript +++ b/intern/itasc/SConscript @@ -9,8 +9,5 @@ incs = '. ../../extern/Eigen3' defs = [] -if env['PLATFORM'] == 'win32': - defs.append('EIGEN_DONT_ALIGN_STATICALLY') - env.BlenderLib ('bf_intern_itasc', sources, Split(incs), defs, libtype=['intern','player'], priority=[20,100] ) diff --git a/intern/itasc/kdl/jntarray.cpp b/intern/itasc/kdl/jntarray.cpp index 77c75e6af6c..db2c913a532 100644 --- a/intern/itasc/kdl/jntarray.cpp +++ b/intern/itasc/kdl/jntarray.cpp @@ -71,20 +71,25 @@ namespace KDL SetToZero(*this); } - double JntArray::operator()(unsigned int i,unsigned int j)const + double JntArray::operator[](unsigned int i)const { - assert(i<size&&j==0); - assert(0 != size); // found JntArray containing no data + assert(i<size); return data[i]; } - double& JntArray::operator()(unsigned int i,unsigned int j) + double& JntArray::operator[](unsigned int i) { - assert(i<size&&j==0); - assert(0 != size); // found JntArray containing no data + assert(i<size); return data[i]; } + double* JntArray::operator()(unsigned int i) + { + if (i>=size) + return NULL; + return &data[i]; + } + unsigned int JntArray::rows()const { return size; diff --git a/intern/itasc/kdl/jntarray.hpp b/intern/itasc/kdl/jntarray.hpp index 8db4cd6f2b3..ece6b0bdb6b 100644 --- a/intern/itasc/kdl/jntarray.hpp +++ b/intern/itasc/kdl/jntarray.hpp @@ -107,24 +107,30 @@ class MyTask : public RTT::TaskContext JntArray& operator = ( const JntArray& arg); /** - * get_item operator for the joint array, if a second value is - * given it should be zero, since a JntArray resembles a column. + * get_item operator for the joint array * * * @return the joint value at position i, starting from 0 * @pre 0 != size (ie non-default constructor or resize() called) */ - double operator()(unsigned int i,unsigned int j=0)const; + double operator[](unsigned int i) const; /** - * set_item operator, again if a second value is given it - *should be zero. + * set_item operator * * @return reference to the joint value at position i,starting *from zero. * @pre 0 != size (ie non-default constructor or resize() called) */ - double& operator()(unsigned int i,unsigned int j=0); + double& operator[](unsigned int i); /** + * access operator for the joint array. Use pointer here to allow + * access to sequential joint angles (required for ndof joints) + * + * + * @return the joint value at position i, NULL if i is outside the valid range + */ + double* operator()(unsigned int i); + /** * Returns the number of rows (size) of the array * */ diff --git a/intern/itasc/kdl/joint.cpp b/intern/itasc/kdl/joint.cpp index 5458efc4fcf..161794ddd72 100644 --- a/intern/itasc/kdl/joint.cpp +++ b/intern/itasc/kdl/joint.cpp @@ -55,37 +55,45 @@ namespace KDL { { } - Frame Joint::pose(const double& q)const + Frame Joint::pose(const double* q)const { switch(type){ case RotX: - return Frame(Rotation::RotX(scale*q+offset)); + assert(q); + return Frame(Rotation::RotX(scale*q[0]+offset)); break; case RotY: - return Frame(Rotation::RotY(scale*q+offset)); + assert(q); + return Frame(Rotation::RotY(scale*q[0]+offset)); break; case RotZ: - return Frame(Rotation::RotZ(scale*q+offset)); + assert(q); + return Frame(Rotation::RotZ(scale*q[0]+offset)); break; case TransX: - return Frame(Vector(scale*q+offset,0.0,0.0)); + assert(q); + return Frame(Vector(scale*q[0]+offset,0.0,0.0)); break; case TransY: - return Frame(Vector(0.0,scale*q+offset,0.0)); + assert(q); + return Frame(Vector(0.0,scale*q[0]+offset,0.0)); break; case TransZ: - return Frame(Vector(0.0,0.0,scale*q+offset)); + assert(q); + return Frame(Vector(0.0,0.0,scale*q[0]+offset)); break; case Sphere: // the joint angles represent a rotation vector expressed in the base frame of the joint // (= the frame you get when there is no offset nor rotation) - return Frame(Rot(Vector((&q)[0], (&q)[1], (&q)[2]))); + assert(q); + return Frame(Rot(Vector(q[0], q[1], q[2]))); break; case Swing: // the joint angles represent a 2D rotation vector in the XZ planee of the base frame of the joint // (= the frame you get when there is no offset nor rotation) - return Frame(Rot(Vector((&q)[0], 0.0, (&q)[1]))); + assert(q); + return Frame(Rot(Vector(q[0], 0.0, q[1]))); break; default: return Frame::Identity(); diff --git a/intern/itasc/kdl/joint.hpp b/intern/itasc/kdl/joint.hpp index a1291509f0f..9d25b427499 100644 --- a/intern/itasc/kdl/joint.hpp +++ b/intern/itasc/kdl/joint.hpp @@ -70,7 +70,7 @@ namespace KDL { * * @return the resulting 6D-pose */ - Frame pose(const double& q)const; + Frame pose(const double* q)const; /** * Request the resulting 6D-velocity with a joint velocity qdot * diff --git a/intern/itasc/kdl/kinfam_io.cpp b/intern/itasc/kdl/kinfam_io.cpp index 15557ab5f05..ff4cab862ce 100644 --- a/intern/itasc/kdl/kinfam_io.cpp +++ b/intern/itasc/kdl/kinfam_io.cpp @@ -76,7 +76,7 @@ std::istream& operator >>(std::istream& is, Tree& tree) { std::ostream& operator <<(std::ostream& os, const JntArray& array) { os << "["; for (unsigned int i = 0; i < array.rows(); i++) - os << std::setw(KDL_FRAME_WIDTH) << array(i); + os << std::setw(KDL_FRAME_WIDTH) << array[i]; os << "]"; return os; } diff --git a/intern/itasc/kdl/segment.cpp b/intern/itasc/kdl/segment.cpp index cba797899e1..f963559c4c8 100644 --- a/intern/itasc/kdl/segment.cpp +++ b/intern/itasc/kdl/segment.cpp @@ -48,12 +48,12 @@ namespace KDL { { } - Frame Segment::pose(const double& q)const + Frame Segment::pose(const double* q)const { return joint.pose(q)*f_tip; } - Twist Segment::twist(const double& q, const double& qdot, int dof)const + Twist Segment::twist(const double* q, const double& qdot, int dof)const { return joint.twist(qdot, dof).RefPoint(pose(q).p); } diff --git a/intern/itasc/kdl/segment.hpp b/intern/itasc/kdl/segment.hpp index 87d972ead70..130bfb13f8b 100644 --- a/intern/itasc/kdl/segment.hpp +++ b/intern/itasc/kdl/segment.hpp @@ -73,7 +73,7 @@ namespace KDL { * * @return pose from the root to the tip of the segment */ - Frame pose(const double& q)const; + Frame pose(const double* q)const; /** * Request the 6D-velocity of the tip of the segment, given * the joint position q and the joint velocity qdot. @@ -85,7 +85,7 @@ namespace KDL { *in the base-frame of the segment(root) and with the tip of *the segment as reference point. */ - Twist twist(const double& q,const double& qdot, int dof=0)const; + Twist twist(const double* q,const double& qdot, int dof=0)const; /** * Request the 6D-velocity at a given point p, relative to base frame of the segment diff --git a/intern/itasc/kdl/utilities/utility.h b/intern/itasc/kdl/utilities/utility.h index fbf9982665a..892b375d442 100644 --- a/intern/itasc/kdl/utilities/utility.h +++ b/intern/itasc/kdl/utilities/utility.h @@ -27,6 +27,10 @@ #include <cassert> #include <cmath> +#ifdef NDEBUG +#undef assert +#define assert(e) ((void)0) +#endif ///////////////////////////////////////////////////////////// // configurable options for the frames library. diff --git a/intern/mikktspace/mikktspace.c b/intern/mikktspace/mikktspace.c index cba4c406759..0a3141d6782 100644 --- a/intern/mikktspace/mikktspace.c +++ b/intern/mikktspace/mikktspace.c @@ -40,8 +40,7 @@ #define INTERNAL_RND_SORT_SEED 39871946 // internal structure -typedef struct -{ +typedef struct { float x, y, z; } SVec3; @@ -119,14 +118,12 @@ static tbool VNotZero(const SVec3 v) -typedef struct -{ +typedef struct { int iNrFaces; int * pTriMembers; } SSubGroup; -typedef struct -{ +typedef struct { int iNrFaces; int * pFaceIndices; int iVertexRepresentitive; @@ -141,8 +138,7 @@ typedef struct -typedef struct -{ +typedef struct { int FaceNeighbors[3]; SGroup * AssignedGroup[3]; @@ -156,8 +152,7 @@ typedef struct unsigned char vert_num[4]; } STriInfo; -typedef struct -{ +typedef struct { SVec3 vOs; float fMagS; SVec3 vOt; @@ -426,8 +421,7 @@ tbool genTangSpace(const SMikkTSpaceContext * pContext, const float fAngularThre /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -typedef struct -{ +typedef struct { float vert[3]; int index; } STmpVert; @@ -911,8 +905,7 @@ static SVec3 GetTexCoord(const SMikkTSpaceContext * pContext, const int index) ///////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////// -typedef union -{ +typedef union { struct { int i0, i1, f; diff --git a/intern/mikktspace/mikktspace.h b/intern/mikktspace/mikktspace.h index dc2308f6116..52c44a713c6 100644 --- a/intern/mikktspace/mikktspace.h +++ b/intern/mikktspace/mikktspace.h @@ -62,8 +62,7 @@ extern "C" { typedef int tbool; typedef struct SMikkTSpaceContext SMikkTSpaceContext; -typedef struct -{ +typedef struct { // Returns the number of faces (triangles/quads) on the mesh to be processed. int (*m_getNumFaces)(const SMikkTSpaceContext * pContext); |