Example #1
0
void View::construct ()
{
	m_viewproj = matrix4_multiplied_by_matrix4(matrix4_multiplied_by_matrix4(m_scissor, m_projection), m_modelview);

	m_frustum = frustum_from_viewproj(m_viewproj);
	m_viewer = viewer_from_viewproj(m_viewproj);
}
Example #2
0
void RotateManipulator::testSelect (const View& view, const Matrix4& pivot2world)
{
    m_pivot.update(pivot2world, view.GetModelview(), view.GetProjection(), view.GetViewport());
    updateCircleTransforms();

    SelectionPool selector;

    {
        {
            Matrix4 local2view(matrix4_multiplied_by_matrix4(view.GetViewMatrix(), m_local2world_x));

            SelectionIntersection best;
            LineStrip_BestPoint(local2view, m_circle_x.m_vertices.data(), m_circle_x.m_vertices.size(), best);
            selector.addSelectable(best, &m_selectable_x);
        }

        {
            Matrix4 local2view(matrix4_multiplied_by_matrix4(view.GetViewMatrix(), m_local2world_y));

            SelectionIntersection best;
            LineStrip_BestPoint(local2view, m_circle_y.m_vertices.data(), m_circle_y.m_vertices.size(), best);
            selector.addSelectable(best, &m_selectable_y);
        }

        {
            Matrix4 local2view(matrix4_multiplied_by_matrix4(view.GetViewMatrix(), m_local2world_z));

            SelectionIntersection best;
            LineStrip_BestPoint(local2view, m_circle_z.m_vertices.data(), m_circle_z.m_vertices.size(), best);
            selector.addSelectable(best, &m_selectable_z);
        }
    }

    {
        Matrix4 local2view(matrix4_multiplied_by_matrix4(view.GetViewMatrix(), m_pivot.m_viewpointSpace));

        {
            SelectionIntersection best;
            LineLoop_BestPoint(local2view, m_circle_screen.m_vertices.data(), m_circle_screen.m_vertices.size(), best);
            selector.addSelectable(best, &m_selectable_screen);
        }

        {
            SelectionIntersection best;
            Circle_BestPoint(local2view, eClipCullCW, m_circle_sphere.m_vertices.data(),
                             m_circle_sphere.m_vertices.size(), best);
            selector.addSelectable(best, &m_selectable_sphere);
        }
    }

    m_axis_screen = m_pivot.m_axis_screen;

    if (!selector.failed()) {
        (*selector.begin()).second->setSelected(true);
    }
}
Example #3
0
void TextureProjection::transformLocked (std::size_t width, std::size_t height, const Plane3& plane,
		const Matrix4& identity2transformed)
{

	Vector3 normalTransformed(matrix4_transformed_direction(identity2transformed, plane.normal()));

	// identity: identity space
	// transformed: transformation
	// stIdentity: base st projection space before transformation
	// stTransformed: base st projection space after transformation
	// stOriginal: original texdef space

	// stTransformed2stOriginal = stTransformed -> transformed -> identity -> stIdentity -> stOriginal

	Matrix4 identity2stIdentity;
	basisForNormal(plane.normal(), identity2stIdentity);

	Matrix4 transformed2stTransformed;
	basisForNormal(normalTransformed, transformed2stTransformed);

	Matrix4 stTransformed2identity(matrix4_affine_inverse(matrix4_multiplied_by_matrix4(transformed2stTransformed,
			identity2transformed)));

	Vector3 originalProjectionAxis(matrix4_affine_inverse(identity2stIdentity).z().getVector3());

	Vector3 transformedProjectionAxis(stTransformed2identity.z().getVector3());

	Matrix4 stIdentity2stOriginal = m_texdef.getTransform((float) width, (float) height);
	Matrix4 identity2stOriginal(matrix4_multiplied_by_matrix4(stIdentity2stOriginal, identity2stIdentity));

	double dot = originalProjectionAxis.dot(transformedProjectionAxis);
	if (dot == 0) {
		// The projection axis chosen for the transformed normal is at 90 degrees
		// to the transformed projection axis chosen for the original normal.
		// This happens when the projection axis is ambiguous - e.g. for the plane
		// 'X == Y' the projection axis could be either X or Y.

		Matrix4 identityCorrected = matrix4_reflection_for_plane45(plane, originalProjectionAxis,
				transformedProjectionAxis);

		identity2stOriginal = matrix4_multiplied_by_matrix4(identity2stOriginal, identityCorrected);
	}

	Matrix4 stTransformed2stOriginal = matrix4_multiplied_by_matrix4(identity2stOriginal, stTransformed2identity);

	setTransform((float) width, (float) height, stTransformed2stOriginal);
	m_texdef.normalise((float) width, (float) height);
}
inline void matrix4_assign_rotation_for_pivot(Matrix4& matrix, scene::Instance& instance) {
	Editable* editable = Node_getEditable(instance.path().top());
	// If the instance is editable, take the localpivot point into account, otherwise just apply the rotation
	if (editable != 0) {
		matrix4_assign_rotation(matrix, matrix4_multiplied_by_matrix4(instance.localToWorld(), editable->getLocalPivot()));
	}
	else {
		matrix4_assign_rotation(matrix, instance.localToWorld());
	}
}
Example #5
0
void ScaleManipulator::testSelect (const View& view, const Matrix4& pivot2world)
{
    m_pivot.update(pivot2world, view.GetModelview(), view.GetProjection(), view.GetViewport());

    SelectionPool selector;

    {
        Matrix4 local2view(matrix4_multiplied_by_matrix4(view.GetViewMatrix(), m_pivot.m_worldSpace));

        {
            SelectionIntersection best;
            Line_BestPoint(local2view, m_arrow_x.m_line, best);
            selector.addSelectable(best, &m_selectable_x);
        }

        {
            SelectionIntersection best;
            Line_BestPoint(local2view, m_arrow_y.m_line, best);
            selector.addSelectable(best, &m_selectable_y);
        }

        {
            SelectionIntersection best;
            Line_BestPoint(local2view, m_arrow_z.m_line, best);
            selector.addSelectable(best, &m_selectable_z);
        }
    }

    {
        Matrix4 local2view(matrix4_multiplied_by_matrix4(view.GetViewMatrix(), m_pivot.m_viewpointSpace));

        {
            SelectionIntersection best;
            Quad_BestPoint(local2view, eClipCullCW, m_quad_screen.m_quad, best);
            selector.addSelectable(best, &m_selectable_screen);
        }
    }

    if (!selector.failed()) {
        (*selector.begin()).second->setSelected(true);
    }
}
/* greebo: This is called by the ManipulateObserver class on the mouseDown event. It checks, if a manipulator
 * can be selected where the mouse is pointing to.
 */
bool RadiantSelectionSystem::SelectManipulator(const View& view, const float device_point[2], const float device_epsilon[2]) {
	if (!nothingSelected() || (ManipulatorMode() == eDrag && Mode() == eComponent)) {
#if defined (DEBUG_SELECTION)
		g_render_clipped.destroy();
#endif

		// Unselect any currently selected manipulators to be sure
		_manipulator->setSelected(false);

		// Test, if the current manipulator can be selected
		if (!nothingSelected() || (ManipulatorMode() == eDrag && Mode() == eComponent)) {
			View scissored(view);
			ConstructSelectionTest(scissored, SelectionBoxForPoint(device_point, device_epsilon));

			// The manipulator class checks on its own, if any of its components can be selected
			_manipulator->testSelect(scissored, GetPivot2World());
		}

		// Save the pivot2world matrix
		startMove();

		// This is true, if a manipulator could be selected
		_pivotMoving = _manipulator->isSelected();

		// is a manipulator selected / the pivot moving?
		if (_pivotMoving) {
			Pivot2World pivot;
			pivot.update(GetPivot2World(), view.GetModelview(), view.GetProjection(), view.GetViewport());

			_manip2pivotStart = matrix4_multiplied_by_matrix4(matrix4_full_inverse(_pivot2worldStart), pivot.m_worldSpace);

			Matrix4 device2manip;
			ConstructDevice2Manip(device2manip, _pivot2worldStart, view.GetModelview(), view.GetProjection(), view.GetViewport());
			_manipulator->GetManipulatable()->Construct(device2manip, device_point[0], device_point[1]);

			_undoBegun = false;
		}

		SceneChangeNotify();
	}

	return _pivotMoving;
}
Example #7
0
void CPortalsRender::renderSolid( Renderer& renderer, const VolumeTest& volume ) const {
	if ( !portals.show_3d || portals.portal_count < 1 ) {
		return;
	}

	CubicClipVolume clip = calculateCubicClipVolume( matrix4_multiplied_by_matrix4( volume.GetProjection(), volume.GetModelview() ) );

	if ( portals.polygons ) {
		renderer.SetState( g_shader_solid, Renderer::eWireframeOnly );
		renderer.SetState( g_shader_solid, Renderer::eFullMaterials );

		m_drawSolid.clip = clip;
		renderer.addRenderable( m_drawSolid, g_matrix4_identity );
	}

	if ( portals.lines ) {
		renderer.SetState( g_shader_solid_outline, Renderer::eWireframeOnly );
		renderer.SetState( g_shader_solid_outline, Renderer::eFullMaterials );

		m_drawSolidOutline.clip = clip;
		renderer.addRenderable( m_drawSolidOutline, g_matrix4_identity );
	}
}
Example #8
0
void TranslateManipulator::testSelect (const View& view, const Matrix4& pivot2world)
{
    m_pivot.update(pivot2world, view.GetModelview(), view.GetProjection(), view.GetViewport());

    SelectionPool selector;

    Vector3 x = m_pivot.m_worldSpace.x().getVector3().getNormalised();
    bool show_x = manipulator_show_axis(m_pivot, x);

    Vector3 y = m_pivot.m_worldSpace.y().getVector3().getNormalised();
    bool show_y = manipulator_show_axis(m_pivot, y);

    Vector3 z = m_pivot.m_worldSpace.z().getVector3().getNormalised();
    bool show_z = manipulator_show_axis(m_pivot, z);

    {
        Matrix4 local2view(matrix4_multiplied_by_matrix4(view.GetViewMatrix(), m_pivot.m_viewpointSpace));

        {
            SelectionIntersection best;
            Quad_BestPoint(local2view, eClipCullCW, m_quad_screen.m_quad, best);
            if (best.valid()) {
                best = SelectionIntersection(0, 0);
                selector.addSelectable(best, &m_selectable_screen);
            }
        }
    }

    {
        Matrix4 local2view(matrix4_multiplied_by_matrix4(view.GetViewMatrix(), m_pivot.m_worldSpace));

#if defined(DEBUG_SELECTION)
        g_render_clipped.construct(view.GetViewMatrix());
#endif

        if (show_x) {
            SelectionIntersection best;
            Line_BestPoint(local2view, m_arrow_x.m_line, best);
            Triangles_BestPoint(local2view, eClipCullCW, m_arrow_head_x.m_vertices.begin(),
                                m_arrow_head_x.m_vertices.end(), best);
            selector.addSelectable(best, &m_selectable_x);
        }

        if (show_y) {
            SelectionIntersection best;
            Line_BestPoint(local2view, m_arrow_y.m_line, best);
            Triangles_BestPoint(local2view, eClipCullCW, m_arrow_head_y.m_vertices.begin(),
                                m_arrow_head_y.m_vertices.end(), best);
            selector.addSelectable(best, &m_selectable_y);
        }

        if (show_z) {
            SelectionIntersection best;
            Line_BestPoint(local2view, m_arrow_z.m_line, best);
            Triangles_BestPoint(local2view, eClipCullCW, m_arrow_head_z.m_vertices.begin(),
                                m_arrow_head_z.m_vertices.end(), best);
            selector.addSelectable(best, &m_selectable_z);
        }
    }

    if (!selector.failed()) {
        (*selector.begin()).second->setSelected(true);
    }
}
Example #9
0
Matrix4 testMatrix4MultipliedConstant1(const Matrix4& a)
{
  return matrix4_multiplied_by_matrix4(a, g_matrix4_identity);
}
Example #10
0
Matrix4 testMatrix4Multiplied1(const Matrix4& a, const Matrix4& b)
{
  return matrix4_multiplied_by_matrix4(a, matrix4_multiplied_by_matrix4(a, b));
}