예제 #1
0
float4x4 Scale(float x, float y, float z)
{
    return float4x4(x, 0, 0, 0,
        0, y, 0, 0,
        0, 0, z, 0,
        0, 0, 0, 1.0f);
}
예제 #2
0
inline float4x4 operator *(const float4x4& m1, const float4x4& m2) {
	const float4x4 m3 = transpose(m2);
	return float4x4(float4(dot(m1.s, m3.s), dot(m1.s, m3.t), dot(m1.s, m3.u), dot(m1.s, m3.v)),
		       				float4(dot(m1.t, m3.s), dot(m1.t, m3.t), dot(m1.t, m3.u), dot(m1.t, m3.v)),
		       				float4(dot(m1.u, m3.s), dot(m1.u, m3.t), dot(m1.u, m3.u), dot(m1.u, m3.v)),
		       				float4(dot(m1.v, m3.s), dot(m1.v, m3.t), dot(m1.v, m3.u), dot(m1.v, m3.v)));
}
예제 #3
0
void
ClipExample::
resize(ivec2 new_size, ivec2 old_size)
{
  float_orthogonal_projection_params proj_params(0, new_size.x(), new_size.y(), 0);
  m_layer->simulation_matrix(WRATHLayer::projection_matrix, float4x4(proj_params));
  glViewport(0, 0, new_size.x(), new_size.y());

  WRATHDefaultRectAttributePacker::Rect::handle rect;  
  
  rect=WRATHNew WRATHDefaultRectAttributePacker::Rect(new_size.x(), new_size.y());
  rect->m_brush_stretch=vec2(m_images[0]->size())/vec2(new_size);
  m_background_widget->set_parameters(rect); 

  rect->m_brush_stretch=vec2(m_images[1]->size())/vec2(new_size);
  m_background_widget2->set_parameters(rect);

  
  for(unsigned int i=0, endi=m_widgets.size(); i<endi; ++i)
    {
      vec2 pos;
      pos=m_widgets[i]->position();
      pos.x()*=static_cast<float>(new_size.x())/static_cast<float>(old_size.x());
      pos.y()*=static_cast<float>(new_size.y())/static_cast<float>(old_size.y());
      m_widgets[i]->position(pos);
    }
}
예제 #4
0
void RenderCircle(Shader *sh, Primitive prim, int segments, float radius)
{
    assert(segments >= 3);

    auto &vbo = circlevbos[segments];

    if (!vbo)
    {
        auto vbuf = new float3[segments];

        float step = PI * 2 / segments;
        for (int i = 0; i < segments; i++)
        {
            // + 1 to reduce "aliasing" from exact 0 / 90 degrees points
            vbuf[i] = float3(sinf(i * step + 1),
                             cosf(i * step + 1), 0);
        }

        vbo = GenBO(GL_ARRAY_BUFFER, sizeof(float3), segments, vbuf);
        delete[] vbuf;
    }

    Transform2D(float4x4(float4(float2_1 * radius, 1)), [&]()
    {
        sh->Set();
        RenderArray(prim, segments, segments, "P", sizeof(float3), vbo);
    });
}
예제 #5
0
float4x4 Translate(float x, float y, float z)
{
    return float4x4(1.0f, 0, 0, x,
        0, 1.0f, 0, y,
        0, 0, 1.0f, z,
        0, 0, 0, 1.0f);
}
예제 #6
0
    // this method updates the projection matrix based on new parameters
void BasicCamera::SetProjectionParameters(
    _In_ float minimumFieldOfView,  // the minimum horizontal or vertical field of view, in degrees
    _In_ float aspectRatio,         // the aspect ratio of the projection (width / height)
    _In_ float nearPlane,           // depth to map to 0
    _In_ float farPlane             // depth to map to 1
    )
{
    float minScale = 1.0f / tan(minimumFieldOfView * PI_F / 360.0f);
    float xScale = 1.0f;
    float yScale = 1.0f;
    if (aspectRatio < 1.0f)
    {
        xScale = minScale;
        yScale = minScale * aspectRatio;
    }
    else
    {
        xScale = minScale / aspectRatio;
        yScale = minScale;
    }
    float zScale = farPlane / (farPlane - nearPlane);
    m_projection = float4x4(
        xScale, 0.0f,   0.0f,    0.0f,
        0.0f,   yScale, 0.0f,    0.0f,
        0.0f,   0.0f,   -zScale, -nearPlane*zScale,
        0.0f,   0.0f,   -1.0f,   0.0f
        );
}
예제 #7
0
float4x4 Translate(const float3& offset)
{
    return float4x4(1.0f, 0, 0, offset.x,
        0, 1.0f, 0, offset.y,
        0, 0, 1.0f, offset.z,
        0, 0, 0, 1.0f);
}
예제 #8
0
float4x4 Scale(const float3& offset)
{
    return float4x4(offset.x, 0, 0, 0,
        0, offset.y, 0, 0,
        0, 0, offset.z, 0,
        0, 0, 0, 1.0f);
}
예제 #9
0
void
BrushExample::
resize(int width, int height)
{
  float_orthogonal_projection_params proj_params(0, width, height, 0);
  m_layer->simulation_matrix(WRATHLayer::projection_matrix, float4x4(proj_params));
  glViewport(0, 0, width, height);
}
예제 #10
0
파일: Quat.cpp 프로젝트: Garfield-Chen/tng
float4x4 MUST_USE_RESULT Quat::ToFloat4x4(const float3 &translation) const
{
#if defined(MATH_AUTOMATIC_SSE) && defined(MATH_SSE)
	return ToFloat4x4(float4(translation, 1.f));
#else
	return float4x4(*this, translation);
#endif
}
예제 #11
0
float4x4 ortho_rh(float width, float height, float near, float far)
{
	return float4x4(
    float4(2.0f / width, 0.0f,          0.0f,              0.0f),
    float4(0.0f,         2.0f / height, 0.0f,              0.0f),
    float4(0.0f,         0.0f,          1.0f / (near-far), 0.0f),
    float4(0.0f,         0.0f,          near / (near-far), 1.0f));
}
예제 #12
0
float4x4 ortho_offcenter_rh(float left, float right, float bottom, float top, float near, float far)
{
	return float4x4(
    float4(2.0f / (right-left),         0.0f,                        0.0f,              0.0f),
    float4(0.0f,                        2.0f / (top-bottom),         0.0f,              0.0f),
    float4(0.0f,                        0.0f,                        1.0f / (near-far), 0.0f),
    float4((left+right) / (left-right), (top+bottom) / (bottom-top), near / (near-far), 1.0f));
}
예제 #13
0
float4x4 proj_offcenter_lh(float left, float right, float bottom, float top, float near, float far)
{
	float2 d = depth_constants_offcenter_lh(near, far);
	return float4x4(
    float4((2.0f*near) / (right-left),  0.0f,                        0.0f, 0.0f),
    float4(0.0f,                        (2.0f*near) / (top-bottom),  0.0f, 0.0f),
    float4((left+right) / (left-right), (top+bottom) / (bottom-top),  d.x, 1.0f),
    float4(0.0f,                        0.0f,                         d.y, 0.0f));
}
예제 #14
0
void RenderLine2D(Shader *sh, Primitive prim, const float3 &v1, const float3 &v2, float thickness)
{
    auto v = (v2 - v1) / 2;
    auto len = length(v);
    auto vnorm = v / len;
    auto trans = translation(v1 + v) * 
                 rotationZ(vnorm.xy()) *
                 float4x4(float4(len, thickness / 2, 1, 1));
    RenderQuad(sh, prim, true, trans);
}
예제 #15
0
float4x4 proj_inv_fovy_lh(float fovy_radians, float aspect_ratio, float near, float far)
{
	const float2 s = scale_rcp_constants_fovy(fovy_radians, aspect_ratio);
	const float2 d = proj_inv_depth_constants_lh(near, far);
	return float4x4(
		float4(s.x,  0.0f, 0.0f, 0.0f),
		float4(0.0f, s.y,  0.0f, 0.0f),
		float4(0.0f, 0.0f, 0.0f, d.y),
		float4(0.0f, 0.0f, 1.0f, d.x));
}
예제 #16
0
float4x4 proj_fovx_rh(float fovx_radians, float aspect_ratio, float near, float far)
{
	const float2 s = scale_constants_fovx(fovx_radians, aspect_ratio);
	const float2 d = depth_constants_rh(near, far);
	return float4x4(
		float4(s.x,  0.0f, 0.0f, 0.0f),
		float4(0.0f, s.y,  0.0f, 0.0f),
		float4(0.0f, 0.0f, d.x, -1.0f),
		float4(0.0f, 0.0f, d.y,  0.0f));
}
예제 #17
0
파일: scene_d2d.cpp 프로젝트: ghub/NVprSDK
///////////////////////////////////////////////////////////////////////////////
// Draw
Draw::Draw(D2DRendererPtr renderer_) 
    : renderer(renderer_)
{
    matrix_stack.pop();
    matrix_stack.push(float4x4(
        renderer->m_mViewMatrix._11, renderer->m_mViewMatrix._21, 0, renderer->m_mViewMatrix._31,
        renderer->m_mViewMatrix._12, renderer->m_mViewMatrix._22, 0, renderer->m_mViewMatrix._32,
        0,0,1,0,
        0,0,0,1));
}
예제 #18
0
void Set3DMode(float fovy, float ratio, float znear, float zfar)
{
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);  

    otransforms = objecttransforms();

    view2clip = perspectiveFov(fovy, ratio, znear, zfar, 1);
    view2clip *= float4x4(float4(1, -1, 1, 1)); // FIXME?
}
예제 #19
0
파일: Quat.cpp 프로젝트: chengzg/MathGeoLib
float4x4 MUST_USE_RESULT Quat::ToFloat4x4() const
{
	assume(IsNormalized());
#if defined(MATH_AUTOMATIC_SSE) && defined(MATH_SSE)
	float4x4 m;
	quat_to_mat4x4(q, _mm_set_ps(1,0,0,0), m.row);
	return m;
#else
	return float4x4(*this);
#endif
}
예제 #20
0
파일: Quat.cpp 프로젝트: chengzg/MathGeoLib
float4x4 MUST_USE_RESULT Quat::ToFloat4x4(const float4 &translation) const
{
	assume(IsNormalized());
#if defined(MATH_AUTOMATIC_SSE) && defined(MATH_SSE)
	float4x4 m;
	quat_to_mat4x4(q, translation.v, m.row);
	return m;
#else
	return float4x4(*this, translation.xyz());
#endif
}
예제 #21
0
	int KungFuPOC::InitPainting()
	{
		painting = new Painting(device, deviceContext);
		painting->SetTransformMatrix(
			float4x4(
				1.0f, 0.0f, 0.0f, 0.0f,
				0.0f, 1.0f, 0.0f, 0.0f,
				0.0f, 0.0f, 1.0f, 0.0f,
				0.0f, 0.0f, PAINTING_Z, 1.0f
			)
		);
		return 0;
	}
예제 #22
0
void RenderLine3D(Shader *sh, const float3 &v1, const float3 &v2, const float3 &/*campos*/, float thickness)
{
    glDisable(GL_CULL_FACE);  // An exception in 3d mode.
    // FIXME: need to rotate the line also to make it face the camera.
    //auto camvec = normalize(campos - (v1 + v2) / 2);
    auto v = v2 - v1;
    auto vq = quatfromtwovectors(normalize(v), float3_x);
    //auto sq = quatfromtwovectors(camvec, float3_z);
    auto trans = translation((v1 + v2) / 2) * 
                 float3x3to4x4(rotation(vq)) *  // FIXME: cheaper?
                 float4x4(float4(length(v) / 2, thickness, 1, 1));
    RenderQuad(sh, PRIM_FAN, true, trans);
    glEnable(GL_CULL_FACE); 
}
예제 #23
0
//-----------------------------------------------------------------------------
void CPUTCamera::LookAt( const float xx, const float yy, const float zz )
{
    float3 pos;
    GetPosition( &pos);

    float3 lookPoint(xx, yy, zz);
    float3 look  = (lookPoint - pos).normalize();
    float3 right = cross3(float3(0.0f,1.0f,0.0f), look).normalize(); // TODO: simplify algebraically
    float3 up    = cross3(look, right);
    
    mParentMatrix = float4x4(
        right.x, right.y, right.z, 0.0f,
           up.x,    up.y,    up.z, 0.0f,
         look.x,  look.y,  look.z, 0.0f,
          pos.x,   pos.y,   pos.z, 1.0f
    );
}
예제 #24
0
void RenderOpenCircle(Shader *sh, int segments, float radius, float thickness)
{
    assert(segments >= 3);

    auto vbo_type = make_pair(segments, thickness);
    auto &vibo = opencirclevbos[vbo_type];

    auto nverts = segments * 2;
    auto nindices = segments * 6;

    if (!vibo.first)
    {
        auto vbuf = new float3[nverts];
        auto ibuf = new int[nindices];

        float step = PI * 2 / segments;
        float inner = 1 - thickness;
        for (int i = 0; i < segments; i++)
        {
            // + 1 to reduce "aliasing" from exact 0 / 90 degrees points
            float x = sinf(i * step + 1);
            float y = cosf(i * step + 1);
            vbuf[i * 2 + 0] = float3(x, y, 0);
            vbuf[i * 2 + 1] = float3(x * inner, y * inner, 0);
            ibuf[i * 6 + 0] = i * 2 + 0;
            ibuf[i * 6 + 1] = ((i + 1) * 2 + 0) % nverts;
            ibuf[i * 6 + 2] = i * 2 + 1;
            ibuf[i * 6 + 3] = i * 2 + 1;
            ibuf[i * 6 + 4] = ((i + 1) * 2 + 1) % nverts;
            ibuf[i * 6 + 5] = ((i + 1) * 2 + 0) % nverts;
        }

        vibo.first = GenBO(GL_ARRAY_BUFFER, sizeof(float3), nverts, vbuf);
        vibo.second = GenBO(GL_ELEMENT_ARRAY_BUFFER, sizeof(int), nindices, ibuf);
        delete[] vbuf;
        delete[] ibuf;
    }

    Transform2D(float4x4(float4(float2_1 * radius, 1)), [&]()
    {
        sh->Set();
        RenderArray(PRIM_TRIS, nindices, nverts, "P", sizeof(float3), vibo.first, vibo.second);
    });
}
예제 #25
0
// this method updates the view matrix based on new position and focus coordinates
void BasicCamera::SetViewParameters(
    _In_ float3 eyePosition,    // the position of the camera
    _In_ float3 lookPosition,   // the point the camera should look at
    _In_ float3 up              // the durection vector for up
    )
{
    m_position = eyePosition;
    m_direction = normalize(lookPosition - eyePosition);
    float3 zAxis = -m_direction;
    float3 xAxis = normalize(cross(up, zAxis));
    float3 yAxis = cross(zAxis, xAxis);
    float xOffset = -dot(xAxis, m_position);
    float yOffset = -dot(yAxis, m_position);
    float zOffset = -dot(zAxis, m_position);
    m_view = float4x4(
        xAxis.x, xAxis.y, xAxis.z, xOffset,
        yAxis.x, yAxis.y, yAxis.z, yOffset,
        zAxis.x, zAxis.y, zAxis.z, zOffset,
        0.0f,    0.0f,    0.0f,    1.0f
        );
}
예제 #26
0
inline float4x4 inverse(const float4x4& m) {
	return float4x4(
		       determinant(float3x3(m.t.y, m.u.y, m.v.y, m.t.z, m.u.z, m.v.z, m.t.w, m.u.w, m.v.w)),
		      -determinant(float3x3(m.s.y, m.u.y, m.v.y, m.s.z, m.u.z, m.v.z, m.s.w, m.u.w, m.v.w)),
		       determinant(float3x3(m.s.y, m.t.y, m.v.y, m.s.z, m.t.z, m.v.z, m.s.w, m.t.w, m.v.w)),
		      -determinant(float3x3(m.s.y, m.t.y, m.u.y, m.s.z, m.t.z, m.u.z, m.s.w, m.t.w, m.u.w)),

		      -determinant(float3x3(m.t.x, m.u.x, m.v.x, m.t.z, m.u.z, m.v.z, m.t.w, m.u.w, m.v.w)),
		       determinant(float3x3(m.s.x, m.u.x, m.v.x, m.s.z, m.u.z, m.v.z, m.s.w, m.u.w, m.v.w)),
		      -determinant(float3x3(m.s.x, m.t.x, m.v.x, m.s.z, m.t.z, m.v.z, m.s.w, m.t.w, m.v.w)),
		       determinant(float3x3(m.s.x, m.t.x, m.u.x, m.s.z, m.t.z, m.u.z, m.s.w, m.t.w, m.u.w)),

		       determinant(float3x3(m.t.x, m.u.x, m.v.x, m.t.y, m.u.y, m.v.y, m.t.w, m.u.w, m.v.w)),
		      -determinant(float3x3(m.s.x, m.u.x, m.v.x, m.s.y, m.u.y, m.v.y, m.s.w, m.u.w, m.v.w)),
		       determinant(float3x3(m.s.x, m.t.x, m.v.x, m.s.y, m.t.y, m.v.y, m.s.w, m.t.w, m.v.w)),
		      -determinant(float3x3(m.s.x, m.t.x, m.u.x, m.s.y, m.t.y, m.u.y, m.s.w, m.t.w, m.u.w)),

		      -determinant(float3x3(m.t.x, m.u.x, m.v.x, m.t.y, m.u.y, m.v.y, m.t.z, m.u.z, m.v.z)),
		       determinant(float3x3(m.s.x, m.u.x, m.v.x, m.s.y, m.u.y, m.v.y, m.s.z, m.u.z, m.v.z)),
		      -determinant(float3x3(m.s.x, m.t.x, m.v.x, m.s.y, m.t.y, m.v.y, m.s.z, m.t.z, m.v.z)),
		       determinant(float3x3(m.s.x, m.t.x, m.u.x, m.s.y, m.t.y, m.u.y, m.s.z, m.t.z, m.u.z)))

		   * (1.0f / determinant(m));
}
예제 #27
0
파일: Frustum.cpp 프로젝트: Ilikia/naali
float4x4 Frustum::ProjectionMatrix() const
{
    assume(false && "Not implemented!");
    return float4x4();
}
예제 #28
0
float4x4 MUST_USE_RESULT Quat::ToFloat4x4() const
{
	return float4x4(*this);
}
예제 #29
0
inline float4x4 operator *(float f, const float4x4& m)         { return float4x4(m.s * f, m.t * f, m.u * f, m.v * f); }
예제 #30
0
inline float4x4 transpose(const float4x4& m) {
	return float4x4(float4(m.s.x, m.t.x, m.u.x, m.v.x),
	           			float4(m.s.y, m.t.y, m.u.y, m.v.y),
		       				float4(m.s.z, m.t.z, m.u.z, m.v.z),
		       				float4(m.s.w, m.t.w, m.u.w, m.v.w));
}