예제 #1
0
static void rna_Mask_update_parent(Main *bmain, Scene *scene, PointerRNA *ptr)
{
	MaskParent *parent = ptr->data;

	if (parent->id) {
		if (GS(parent->id->name) == ID_MC) {
			MovieClip *clip = (MovieClip *) parent->id;
			MovieTracking *tracking = &clip->tracking;
			MovieTrackingObject *object = BKE_tracking_object_get_named(tracking, parent->parent);

			if (object) {
				MovieTrackingTrack *track = BKE_tracking_track_get_named(tracking, object, parent->sub_parent);

				if (track) {
					int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, scene->r.cfra);
					MovieTrackingMarker *marker = BKE_tracking_marker_get(track, clip_framenr);
					float marker_pos_ofs[2], parmask_pos[2];
					MovieClipUser user = {0};

					BKE_movieclip_user_set_frame(&user, scene->r.cfra);

					add_v2_v2v2(marker_pos_ofs, marker->pos, track->offset);

					BKE_mask_coord_from_movieclip(clip, &user, parmask_pos, marker_pos_ofs);

					copy_v2_v2(parent->parent_orig, parmask_pos);
				}
			}
		}
	}

	rna_Mask_update_data(bmain, scene, ptr);
}
void TrackPositionOperation::initExecution()
{
	MovieTracking *tracking = NULL;
	MovieClipUser user = {0};
	MovieTrackingObject *object;

	zero_v2(this->m_markerPos);
	zero_v2(this->m_relativePos);

	if (!this->m_movieClip)
		return;

	tracking = &this->m_movieClip->tracking;

	BKE_movieclip_user_set_frame(&user, this->m_framenumber);
	BKE_movieclip_get_size(this->m_movieClip, &user, &this->m_width, &this->m_height);

	object = BKE_tracking_object_get_named(tracking, this->m_trackingObjectName);
	if (object) {
		MovieTrackingTrack *track;

		track = BKE_tracking_track_get_named(tracking, object, this->m_trackName);

		if (track) {
			MovieTrackingMarker *marker;
			int clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(this->m_movieClip, this->m_framenumber);

			marker = BKE_tracking_marker_get(track, clip_framenr);

			copy_v2_v2(this->m_markerPos, marker->pos);

			if (this->m_position == CMP_TRACKPOS_RELATIVE_START) {
				int i;

				for (i = 0; i < track->markersnr; i++) {
					marker = &track->markers[i];

					if ((marker->flag & MARKER_DISABLED) == 0) {
						copy_v2_v2(this->m_relativePos, marker->pos);

						break;
					}
				}
			}
			else if (this->m_position == CMP_TRACKPOS_RELATIVE_FRAME) {
				int relative_clip_framenr = BKE_movieclip_remap_scene_to_clip_frame(this->m_movieClip,
				                                                                    this->m_relativeFrame);

				marker = BKE_tracking_marker_get(track, relative_clip_framenr);
				copy_v2_v2(this->m_relativePos, marker->pos);
			}
		}
	}
}
void TrackPositionOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler)
{
	MovieClipUser user = {0};
	MovieTracking *tracking = &movieClip->tracking;
	MovieTrackingObject *object = BKE_tracking_object_get_named(tracking, this->trackingObject);
	MovieTrackingTrack *track;
	MovieTrackingMarker *marker;
	int width, height;

	outputValue[0] = 0.0f;

	if (!object)
		return;

	track = BKE_tracking_track_get_named(tracking, object, this->trackName);

	if (!track)
		return;

	BKE_movieclip_user_set_frame(&user, this->framenumber);
	BKE_movieclip_get_size(this->movieClip, &user, &width, &height);

	marker = BKE_tracking_marker_get(track, this->framenumber);

	outputValue[0] = marker->pos[this->axis];

	if (this->relative) {
		int i;

		for (i = 0; i < track->markersnr; i++) {
			marker = &track->markers[i];

			if ((marker->flag & MARKER_DISABLED) == 0) {
				outputValue[0] -= marker->pos[this->axis];

				break;
			}
		}
	}

	if (this->axis == 0)
		outputValue[0] *= width;
	else
		outputValue[0] *= height;
}