void OBSBasicPreview::SnapStretchingToScreen(vec3 &tl, vec3 &br)
{
	uint32_t stretchFlags = (uint32_t)stretchHandle;
	vec3     newTL        = GetTransformedPos(tl.x, tl.y, itemToScreen);
	vec3     newTR        = GetTransformedPos(br.x, tl.y, itemToScreen);
	vec3     newBL        = GetTransformedPos(tl.x, br.y, itemToScreen);
	vec3     newBR        = GetTransformedPos(br.x, br.y, itemToScreen);
	vec3     boundingTL;
	vec3     boundingBR;

	vec3_copy(&boundingTL, &newTL);
	vec3_min(&boundingTL, &boundingTL, &newTR);
	vec3_min(&boundingTL, &boundingTL, &newBL);
	vec3_min(&boundingTL, &boundingTL, &newBR);

	vec3_copy(&boundingBR, &newTL);
	vec3_max(&boundingBR, &boundingBR, &newTR);
	vec3_max(&boundingBR, &boundingBR, &newBL);
	vec3_max(&boundingBR, &boundingBR, &newBR);

	vec3 offset = GetScreenSnapOffset(boundingTL, boundingBR);
	vec3_add(&offset, &offset, &newTL);
	vec3_transform(&offset, &offset, &screenToItem);
	vec3_sub(&offset, &offset, &tl);

	if (stretchFlags & ITEM_LEFT)
		tl.x += offset.x;
	else if (stretchFlags & ITEM_RIGHT)
		br.x += offset.x;

	if (stretchFlags & ITEM_TOP)
		tl.y += offset.y;
	else if (stretchFlags & ITEM_BOTTOM)
		br.y += offset.y;
}
static bool AddItemBounds(obs_scene_t scene, obs_sceneitem_t item,
		void *param)
{
	SelectedItemBounds *data = reinterpret_cast<SelectedItemBounds*>(param);

	if (!obs_sceneitem_selected(item))
		return true;

	matrix4 boxTransform;
	obs_sceneitem_get_box_transform(item, &boxTransform);

	vec3 t[4] = {
		GetTransformedPos(0.0f, 0.0f, boxTransform),
		GetTransformedPos(1.0f, 0.0f, boxTransform),
		GetTransformedPos(0.0f, 1.0f, boxTransform),
		GetTransformedPos(1.0f, 1.0f, boxTransform)
	};

	for (const vec3 &v : t) {
		if (data->first) {
			vec3_copy(&data->tl, &v);
			vec3_copy(&data->br, &v);
			data->first = false;
		} else {
			vec3_min(&data->tl, &data->tl, &v);
			vec3_max(&data->br, &data->br, &v);
		}
	}

	UNUSED_PARAMETER(scene);
	return true;
}
Example #3
0
void bounds_merge_point(struct bounds *dst, const struct bounds *b,
		const struct vec3 *v)
{
	vec3_min(&dst->min, &b->min, v);
	vec3_max(&dst->max, &b->max, v);
}
Example #4
0
void bounds_merge(struct bounds *dst, const struct bounds *b1,
		const struct bounds *b2)
{
	vec3_min(&dst->min, &b1->min, &b2->min);
	vec3_max(&dst->max, &b1->max, &b2->max);
}
Example #5
0
void render(msg_block_t *msg, rt_context_t *rtx, uint32_t *frame_buffer)
{
  uint32_t *pixel;
  float sy = rtx->sheight * 0.5f - rtx->ayc;
  unsigned int y;
  for (y = 0; y < rtx->height; y++)
  {
    uint32_t *src = frame_buffer + (y * SCALE + rtx->yoff) * msg->fbinfo.line_length / sizeof(uint32_t) + rtx->xoff;
    pixel = src;
    float sx = rtx->swidth * -0.5f;
    unsigned int x;
    for (x = 0; x < rtx->width; x++)
    {
      rtx->ray.pos = rtx->eye;
      rtx->ray.dir = normalize(vec3_sub(vec3_set(sx, sy, 0.0f), rtx->eye));
      vec3_t col = vec3_set(0.0f, 0.0f, 0.0f);
      unsigned int j;
      for (j = 0; j < MAXREF; j++)
      {
        trace_ray(rtx);
        if (rtx->hit != NOHIT)
        {
          vec3_t p, n;
          ray_t next;
          p = vec3_add(rtx->ray.pos, vec3_scale(rtx->ray.dir, rtx->dist));
          switch (rtx->obj[rtx->hit].type)
          {
            case SPHERE:
              n = normalize(vec3_sub(p, rtx->obj[rtx->hit].pos));
              break;
            case PLANE:
              n = rtx->obj[rtx->hit].norm;
              break;
            default:
              break;
          }
          next.pos = vec3_add(p, vec3_scale(n, EPSILON));
          vec3_t lv = vec3_sub(rtx->light.pos, p);
          vec3_t l = normalize(lv);
          next.dir = rtx->ray.dir;
          int prev_hit_index = rtx->hit;
          vec3_t hit_obj_col = rtx->obj[rtx->hit].col;
          float diffuse = dot(n, l);
          float specular = dot(rtx->ray.dir, vec3_sub(l, vec3_scale(n, 2.0f * diffuse)));
          diffuse = max(diffuse, 0.0f);
          specular = max(specular, 0.0f);
          specular = power_spec(specular);
          float s1 = 1.0f;
          float s2 = 1.0f;
          if (rtx->obj[rtx->hit].flag_shadow)
          {
            rtx->ray.dir = l;
            rtx->ray.pos = next.pos;
            trace_ray(rtx);
            int shadow = (rtx->dist < norm(lv));
            s1 = shadow ? 0.5f : s1;
            s2 = shadow ? 0.0f : s2;
          }
          col = vec3_add(col, vec3_add(vec3_scale(rtx->light.col, specular * s2), vec3_scale(hit_obj_col, diffuse * s1)));
          if (!rtx->obj[prev_hit_index].flag_refrect)
          {
            break;
          }
          rtx->ray.dir = vec3_sub(next.dir, vec3_scale(n, dot(next.dir, n) * 2.0f));
          rtx->ray.pos = next.pos;
        }
        else
        {
          break;
        }
      }
      col = vec3_min(vec3_max(col, 0.0f), 1.0f);
      uint32_t col2 = 0xff000000 + ((unsigned int)(col.x * 255.0f) << 16) + ((unsigned int)(col.y * 255.0f) << 8) + (unsigned int)(col.z * 255.0f);
      *pixel = col2;
#if SCALE > 1
      *(pixel + 1) = col2;
#endif
#if SCALE > 3
      *(pixel + 2) = col2;
      *(pixel + 3) = col2;
#endif
      pixel += SCALE;
      sx += rtx->ax;
    }
    uint32_t size = rtx->width * SCALE;
    unsigned int i;
    for (i = 1; i < SCALE; i++)
    {
      uint32_t *dst = src + i * msg->fbinfo.line_length / sizeof(uint32_t);
      unsigned int j;
      for (j = 0; j < size; j++)
      {
        dst[j] = src[j];
      }
    }
    sy -= rtx->ay;
  }
}