Пример #1
0
static void moto_object_node_calc_scale(MotoObjectNode *self)
{
    if(self->priv->scale_calculated)
        return;

    // FIXME: Rewrite with moto_value_[g|s]et_[boolean|int|float]_[2|3|4] when them will be implemented!
    gfloat *s = (gfloat *)g_value_peek_pointer(moto_node_get_param_value((MotoNode *)self, "s"));

    gfloat sx = s[0];
    gfloat sy = s[1];
    gfloat sz = s[2];

    matrix44_scale(self->priv->scale_matrix, sx, sy, sz);

    self->priv->scale_calculated = TRUE;
}
Пример #2
0
matrix44
transform_get_world_matrix(const transform &transform)
{
  matrix33 basis = quaternion_get_rotation_matrix(transform.rotation);
  std::array<float, 16> rotation_data;
  rotation_data.at(0) = matrix33_get(basis, 0);
  rotation_data.at(1) = matrix33_get(basis, 1);
  rotation_data.at(2) = matrix33_get(basis, 2);
  rotation_data.at(3) = 0.f;
  
  rotation_data.at(4) = matrix33_get(basis, 3);
  rotation_data.at(5) = matrix33_get(basis, 4);
  rotation_data.at(6) = matrix33_get(basis, 5);
  rotation_data.at(7) = 0.f;
  
  rotation_data.at(8) = matrix33_get(basis, 6);
  rotation_data.at(9) = matrix33_get(basis, 7);
  rotation_data.at(10) = matrix33_get(basis, 8);
  rotation_data.at(11) = 0.f;
  
  rotation_data.at(12) = 0.f;
  rotation_data.at(13) = 0.f;
  rotation_data.at(14) = 0.f;
  rotation_data.at(15) = 1.f;
  
  //matrix33_to_array(basis, &rotation_data[0]);
  
  const matrix44 rotaiton = matrix44_init_with_array(rotation_data);
  
  const auto vec =  transform.position;
  
  const matrix44 translate = matrix44_translate(matrix44_id(), vec);
  
  // Scale
  const float x = caff_math::vector3_get_x(transform.scale);
  const float y = caff_math::vector3_get_y(transform.scale);
  const float z = caff_math::vector3_get_z(transform.scale);
  const matrix44 scale = matrix44_scale(x, y, z);
  
  const matrix44 scale_rotation = caff_math::matrix44_multiply(scale, rotaiton);
  const matrix44 world_matrix = caff_math::matrix44_multiply(scale_rotation, translate);
  
  return world_matrix;
}