void TCompCamera::renderInMenu() {
	float fov_in_rad = getFov();
	float znear = getZNear();
	float zfar = getZFar();
	float ar = getAspectRatio();

	bool changed = false;
	//float fov_in_deg = rad2deg(fov_in_rad);
	//if (ImGui::SliderFloat("Fov", &fov_in_deg, 30.f, 110.f)) {
	//	changed = true;
	//	fov_in_rad = deg2rad(fov_in_deg);
	//}
	if (!isOrtho()) {
		float fov_in_deg = rad2deg(fov_in_rad);
		if (ImGui::DragFloat("Fov", &fov_in_deg, 0.1f, 1.f, 120.f)) {
			changed = true;
			fov_in_rad = deg2rad(clamp(fov_in_deg, 1.f, 120.f));
		}
	}
	changed |= ImGui::DragFloat("ZNear", &znear, 0.01f, 0.01f);
	changed |= ImGui::DragFloat("ZFar", &zfar, 0.01f, 1.f, 1000.f);
	if (changed)
		setProjection(fov_in_rad, znear, zfar);

	if (ImGui::SliderFloat("a/r", &ar, 0.f, 10.f)) {
		//setAspectRatio(ar);
	}
}
void TCompCamera::update(float dt) {
	if (!isOrtho()) updateFromEntityTransform(MY_OWNER);
	else {
		GET_MY(tmx, TCompTransform);
		if (tmx) this->lookAt(tmx->getPosition(), tmx->getPosition() + tmx->getFront());
	}
}
示例#3
0
void MOCamera::enable(void)
{
	MRenderingContext * render = MEngine::getInstance()->getRenderingContext();
	

	// get viewport
	render->getViewport(m_currentViewport);

	// projection mode
	render->setMatrixMode(M_MATRIX_PROJECTION);
	render->loadIdentity();

	float ratio = (m_currentViewport[2] / (float)m_currentViewport[3]);

	MVector3 scale = getTransformedScale();
	MVector3 iScale(1.0f / scale.x, 1.0f / scale.y, 1.0f / scale.z);

	MMatrix4x4 iScaleMatrix;
	iScaleMatrix.setScale(iScale);

	MMatrix4x4 inverseMatrix = ((*getMatrix()) * iScaleMatrix).getInverse();

	// perspective view
	if(! isOrtho())
	{
		// normal perspective projection
		render->setPerspectiveView(m_fov, ratio, m_clippingNear, m_clippingFar);

		// model view mode
		render->setMatrixMode(M_MATRIX_MODELVIEW);
		render->loadIdentity();

		render->multMatrix(&inverseMatrix);

		// get current matrices
		render->getModelViewMatrix(&m_currentViewMatrix);
		render->getProjectionMatrix(&m_currentProjMatrix);
		return;
	}

	// ortho view
	float height = m_fov * 0.5f;
	float width = height * ratio;

	render->setOrthoView(-width, width, -height, height, m_clippingNear, m_clippingFar);

	// model view mode
	render->setMatrixMode(M_MATRIX_MODELVIEW);
	render->loadIdentity();
	
	render->multMatrix(&inverseMatrix);

	// get current matrices
	render->getModelViewMatrix(&m_currentViewMatrix);
	render->getProjectionMatrix(&m_currentProjMatrix);
}
示例#4
0
bool MgEllipse::_draw(int mode, GiGraphics& gs, const GiContext& ctx, int segment) const
{
    bool ret = false;

    if (isOrtho())
    {
        ret = gs.drawEllipse(&ctx, Box2d(_points[0], _points[2]));
    }
    else
    {
        ret = gs.drawBeziers(&ctx, 13, _bzpts, true);
    }

    return __super::_draw(mode, gs, ctx, segment) || ret;
}
示例#5
0
bool MgEllipse::_draw(GiGraphics& gs, const GiContext& ctx) const
{
    bool ret = false;

    if (isOrtho())
    {
        ret = gs.drawEllipse(&ctx, Box2d(_points[0], _points[2]));
    }
    else
    {
        ret = gs.drawBeziers(&ctx, 13, _bzpts);
    }

    return __super::_draw(gs, ctx) || ret;
}
示例#6
0
bool MgRoundRect::_draw(GiGraphics& gs, const GiContext& ctx) const
{
    bool ret = false;

    if (isOrtho())
    {
        ret = gs.drawRoundRect(&ctx, Box2d(_points[0], _points[2]), _rx, _ry);
    }
    else
    {
        GiSaveModelTransform xf(&gs.xf(), Matrix2d::rotation(getAngle(), getCenter()));
        ret = gs.drawRoundRect(&ctx, getRect(), _rx, _ry);
    }

    return __super::_draw(gs, ctx) || ret;
}
示例#7
0
void MOCamera::updateProjMatrix(void)
{
	MRenderingContext * render = MEngine::getInstance()->getRenderingContext();
	render->getViewport(m_currentViewport);
	
	float ratio = (m_currentViewport[2] / (float)m_currentViewport[3]);

	// perspective view
	if(! isOrtho())
	{
		// normal perspective projection
		createPerspectiveView(&m_currentProjMatrix, m_fov, ratio, m_clippingNear, m_clippingFar);
		return;
	}

	// ortho view
	float height = m_fov * 0.5f;
	float width = height * ratio;

	createOrthoView(&m_currentProjMatrix, -width, width, -height, height, m_clippingNear, m_clippingFar);
}
示例#8
0
float MgRoundRect::_hitTest(const Point2d& pt, float tol, 
                            Point2d& nearpt, Int32& segment) const
{
    float dist;

    if (isOrtho())
    {
        dist = mgRoundRectHit(Box2d(_points[0], _points[2]), _rx, _ry, pt, tol, nearpt, segment);
    }
    else
    {
        Matrix2d mat(Matrix2d::rotation(getAngle(), getCenter()));
        Box2d rect(Box2d(pt, 2 * tol, 2 * tol) * mat.inverse());

        dist = mgRoundRectHit(getRect(), _rx, _ry, 
            rect.center(), rect.width(), nearpt, segment);
        if (dist < 1e10)
            nearpt *= mat;
    }

    return dist;
}