Пример #1
0
/** Create or adjust "rot" parameter for a component
 * Assumed that name either equals "rotx", "roty" or "rotz" otherwise this
 * method will not add/modify "rot" parameter
 * @param comp :: Component
 * @param name :: Parameter name
 * @param deg :: Parameter value in degrees
 * @param pDescription :: a pointer (may be NULL) to a string, containing
 * parameter's
 * description. If provided, the contents of the string is copied to the
 * parameter's
 * memory
*/
void ParameterMap::addRotationParam(const IComponent *comp,
                                    const std::string &name, const double deg,
                                    const std::string *const pDescription) {
  Parameter_sptr paramRotX = get(comp, rotx());
  Parameter_sptr paramRotY = get(comp, roty());
  Parameter_sptr paramRotZ = get(comp, rotz());
  double rotX, rotY, rotZ;

  if (paramRotX)
    rotX = paramRotX->value<double>();
  else
    rotX = 0.0;

  if (paramRotY)
    rotY = paramRotY->value<double>();
  else
    rotY = 0.0;

  if (paramRotZ)
    rotZ = paramRotZ->value<double>();
  else
    rotZ = 0.0;

  // adjust rotation
  Quat quat;
  if (name.compare(rotx()) == 0) {
    addDouble(comp, rotx(), deg);
    quat = Quat(deg, V3D(1, 0, 0)) * Quat(rotY, V3D(0, 1, 0)) *
           Quat(rotZ, V3D(0, 0, 1));
  } else if (name.compare(roty()) == 0) {
    addDouble(comp, roty(), deg);
    quat = Quat(rotX, V3D(1, 0, 0)) * Quat(deg, V3D(0, 1, 0)) *
           Quat(rotZ, V3D(0, 0, 1));
  } else if (name.compare(rotz()) == 0) {
    addDouble(comp, rotz(), deg);
    quat = Quat(rotX, V3D(1, 0, 0)) * Quat(rotY, V3D(0, 1, 0)) *
           Quat(deg, V3D(0, 0, 1));
  } else {
    g_log.warning()
        << "addRotationParam() called with unrecognized coordinate symbol: "
        << name;
    return;
  }

  // clear the position cache
  clearPositionSensitiveCaches();

  // finally add or update "pos" parameter
  addQuat(comp, rot(), quat, pDescription);
}
Пример #2
0
void ArcBall::setView( int view )
{
    m_zoom = 1.0;
    m_moveX = 0;
    m_moveY = 0;
    m_oldMoveX = 0;
    m_oldMoveY = 0;
    m_currentRot.setToIdentity();
    m_lastRot.setToIdentity();

    QQuaternion rotx( sqrt(0.5), 0, 0, sqrt(0.5) );
    QQuaternion rot_x( -sqrt(0.5), 0, 0, sqrt(0.5) );
    QQuaternion roty( 0, sqrt(0.5), 0, sqrt(0.5) );
    QQuaternion rot_y( 0, -sqrt(0.5), 0, sqrt(0.5) );
    QQuaternion rotz( 0, 0, sqrt(0.5), sqrt(0.5) );

    if ( view == 2 )
    {
        m_currentRot.rotate( rotz );
        m_currentRot.rotate( rotx );
        m_currentRot.rotate( rotx );
    }
    if ( view == 3 )
    {
        m_currentRot.rotate( rot_x );
        m_currentRot.rotate( rot_y );
    }
}
Пример #3
0
//rotate
void rotate(float rx, float ry, float rz){
    Matrix4f rotx, roty, rotz;
    rotx = Matrix4f::Identity();
    roty = Matrix4f::Identity();
    rotz = Matrix4f::Identity();
    float cosrx, sinrx, cosry, sinry, cosrz, sinrz;
    cosrx = cosf(rx); sinrx = sinf(rx);
    cosry = cosf(ry); sinry = sinf(ry);
    cosrz = cosf(rz); sinrz = sinf(rz);
    
    rotx(1,1) = cosrx; rotx(1,2) = -sinrx;
    rotx(2,1) = sinrx; rotx(2,2) = cosrx;
    
    roty(0,0) = cosry; roty(2,0) = -sinry;
    roty(0,2) = sinry; roty(2,2) = cosry;
    
    rotz(0,0) = cosrz; rotz(0,1) = -sinrz;
    rotz(1,0) = sinrz; rotz(1,1) = cosrz;
    
    model_view.top() *= (rotx * roty * rotz);
}
Пример #4
0
static void linear_vignette_proc( int y, int left, int right, LPTR lpDst,
                                    LPTR lpSrc, int depth,
                                    LPGRADIENT_DATA lpGrad )
{
	int xn;
	LPLONG lptld, lptlD;
	long D;

	lptld = lpGrad->lpld;
	lptlD = lpGrad->lplD;
	D = lpGrad->D;

	for (xn = left; xn <= right; ++xn)
	{
		*lptld++ = WHOLE( rotx(xn, y, lpGrad->x1, lpGrad->y1, lpGrad->cosine,
         lpGrad->sine) );
		*lptlD++ = D;
	}
	(*lpGrad->lpProcessProc)(lpSrc, right-left+1, lpGrad);
}
Пример #5
0
void wxOgre::OnMouseMotion(wxMouseEvent& event)
{
	static float speed = 0.0f;
	static bool dragStart = true;
	static const wxString posInfo(wxT("Pos:X:%03d, Y:%03d Change X:%03d Y:%03d"));
	static Ogre::Quaternion startRot(Ogre::Quaternion::IDENTITY);

	Ogre::LogManager* logMgr = Ogre::LogManager::getSingletonPtr();
	Ogre::Log* log(logMgr->getDefaultLog());
	int left, top, width, height;	
	mCamera->getViewport()->getActualDimensions(left, top, width, height);

	wxPoint pos = event.GetPosition();
	wxPoint change = pos - mPrevPos;

	Ogre::Vector2 changeNorm((Ogre::Real) change.x / (Ogre::Real) width,
							 (Ogre::Real) -change.y / (Ogre::Real) height);
	
	if ((!dragStart) && ((!event.Dragging()) || (!event.LeftIsDown()))) {
 			wxString msg(wxT("Drag End"));
			log->logMessage(Ogre::String(msg.mb_str(wxConvUTF8)));
			dragStart = true;
	}

	if(event.Dragging())
	{
		if (event.LeftIsDown())
		{
			if (mTarget) {
				Ogre::Vector3 objectCentre(mTarget == NULL ? Ogre::Vector3::ZERO : mTarget->getPosition());
				if (dragStart) {
					Ogre::Vector3 cam2Object(mCameraNode->getPosition() - objectCentre);
					mDirection =  cam2Object.normalisedCopy();
					mRadius = cam2Object.length();
					mChangePos = Ogre::Vector2::ZERO;
					dragStart = false;					
					wxString msg(wxT("Drag Start"));
					log->logMessage(Ogre::String(msg.mb_str(wxConvUTF8)));
				}  else {
					Ogre::Vector3 across;
					Ogre::Vector3 up;
					Ogre::Vector3 forward;
					mCamera->getRealOrientation().ToAxes(across, up, forward);
					mChangePos += changeNorm;
					Ogre::Quaternion roty(Ogre::Radian(mChangePos.y * Ogre::Math::PI / 12.0f), across);
					Ogre::Quaternion rotx(Ogre::Radian(mChangePos.x * Ogre::Math::PI / 12.0f), up);					
					Ogre::Quaternion rot(roty * rotx);
					rot.normalise();
					mCameraNode->setPosition(objectCentre + ((rot * mDirection) * mRadius));
 					mCamera->lookAt(objectCentre);
				}
			} 
		}
		else if(event.MiddleIsDown())
		{
			int left, top, width, height;
			mCamera->getViewport()->getActualDimensions(left, top, width, height);

			float speed = 1.0f;
			if (event.ShiftDown())
				speed = 0.1f;
			if (event.ControlDown())
				speed = 10.0f;
			float moveX = ((float)-change.x / (float)width) * mZoomScale * speed;
			float moveY = ((float)change.y / (float)height) * mZoomScale * speed;

			Ogre::Vector3 delta(mCamera->getRealOrientation().xAxis() * moveX);
			delta += mCamera->getRealOrientation().yAxis() * moveY;
			mCamera->setPosition(mCamera->getRealPosition() + delta);
		}
	}
	mPrevPos = pos;
}
Пример #6
0
// rotate about X-axis 
Matrix4D RotateX(float theta)
{ 
	Matrix4D rotx(1, 0, 0, 0, 0, cos(theta), -sin(theta), 0, 0, sin(theta), cos(theta), 0, 0, 0, 0, 1);
	return rotx;
}
Пример #7
0
void GsMat::rotx ( float radians, char fmt )
 {
   rotx ( sinf(radians), cosf(radians), fmt );
 }
Пример #8
0
BOOL GradientImage( LPIMAGE lpImage, LPGRADIENT_PARMS lpParms)
{
	LPFRAME lpFrame;
	RECT rMask;
	LPINT lpD;
	FRMTYPEINFO TypeInfo;
	int dx, dy, iCount;
	int index, prev, next, pi, ni;
	long ldx, ldy, x, y, xs, xe, ys, ye, asqrd, bsqrd, r;
	LPDATAPROC lpVignetteProc;
	ENGINE Engine;
	BOOL   DoHSL;
	GRADIENT_DATA data;
	int res;

   FRMDATATYPE type;
	ImgGetInfo(lpImage, NULL, NULL, NULL, &type);
	if (type == FDT_LINEART)
		return(FALSE);
	if (!(lpFrame = ImgGetBaseEditFrame(lpImage)))
		return(FALSE);
	res = FrameResolution(lpFrame);
	data.x1 = lpParms->x1;
	data.y1 = lpParms->y1;
	data.x2 = lpParms->x2;
	data.y2 = lpParms->y2;
	ResConvertUL(lpParms->iBaseRes, res, &data.x1, &data.y1);
	ResConvertLR(lpParms->iBaseRes, res, &data.x2, &data.y2);
	dx = data.x2 - data.x1;
	dy = data.y2 - data.y1;
	data.SoftTransition = lpParms->SoftTransition;
	data.lpPaletteLUT = NULL;

	if (lpParms->Gradient == IDC_VIGLINEAR || lpParms->Gradient == IDC_VIGRADIAL)
	{
		if (abs(dx) <= 3 && abs(dy) <= 3)
			return(FALSE);
	}
	else
	{
		if (abs(dx) <= 3 || abs(dy) <= 3)
			return(FALSE);
	}

	data.xc = (data.x1 + data.x2) / 2;
	data.yc = (data.y1 + data.y2) / 2;

	if ( (data.nRepetitions = lpParms->RepeatCount) <= 0 )
		data.nRepetitions = 1;

	FrameGetTypeInfo(lpFrame, &TypeInfo);

	DoHSL = (lpParms->VigColorModel+IDC_FIRST_MODEL) != IDC_MODEL_RGB &&
				(TypeInfo.DataType > FDT_GRAYSCALE);

	switch (lpParms->Gradient)
	{
		case IDC_VIGLINEAR:
			data.D = lsqrt(((long)dx*(long)dx)+((long)dy*(long)dy));
			data.sine = FGET(-dy, data.D);
			data.cosine = FGET(dx, data.D);
			data.xr = WHOLE(( rotx(data.x2, data.y2, data.x1, data.y1,
            data.cosine, data.sine) ));
			lpVignetteProc = (LPDATAPROC)linear_vignette_proc;
		break;

		case IDC_VIGRADIAL:
			data.D = lsqrt(((long)dx*(long)dx)+((long)dy*(long)dy));
			lpVignetteProc = (LPDATAPROC)radial_vignette_proc;
		break;

		case IDC_VIGCIRCLE:
			data.x1 = data.xc;
			data.y1 = data.yc;
			data.y2 = data.yc;
			dx = data.x2 - data.x1;
			dy = data.y2 - data.y1;
			if (!dx && !dy)
				return(FALSE);
			data.D = lsqrt(((long)dx*(long)dx)+((long)dy*(long)dy));
			lpVignetteProc = (LPDATAPROC)radial_vignette_proc;
		break;

		case IDC_VIGSQUARE:
		case IDC_VIGRECTANGLE:
			data.ymin = min(data.y1, data.y2);
			data.ymax = max(data.y1, data.y2);
			data.xmin = min(data.x1, data.x2);
			data.xmax = max(data.x1, data.x2);

			ldx = data.xmin-data.xc;		// upper left
			ldy = data.ymin-data.yc;
			data.m1 = (256L * ldy) / ldx;
			data.b1 = data.ymin - ((data.m1 * data.xmin)/256L);
			data.D1 = lsqrt((ldx*ldx)+(ldy*ldy));

			ldx = data.xmax-data.xc;		// upper right
			ldy = data.ymin-data.yc;
			data.m2 = (256L * ldy) / ldx;
			data.b2 = data.ymin - ((data.m2 * data.xmax)/256L);
			data.D2 = lsqrt((ldx*ldx)+(ldy*ldy));

			ldx = data.xmax-data.xc;		// lower right
			ldy = data.ymax-data.yc;
			data.m3 = (256L * ldy) / ldx;
			data.b3 = data.ymax - ((data.m3 * data.xmax)/256L);
			data.D3 = lsqrt((ldx*ldx)+(ldy*ldy));

			ldx = data.xmin-data.xc;		// lower left
			ldy = data.ymax-data.yc;
			data.m4 = (256L * ldy) / ldx;
			data.b4 = data.ymax - ((data.m4 * data.xmin)/256L);
			data.D4 = lsqrt((ldx*ldx)+(ldy*ldy));

			lpVignetteProc = (LPDATAPROC)rectangle_vignette_proc;
		break;

		case IDC_VIGELLIPSE:
			if ( !(data.lpD = (LPINT)Alloc((long)sizeof(int)*(TSIZE+1))) )
			{
				Message(IDS_EMEMALLOC);
				return(FALSE);
			}
			iCount = TSIZE+1;
			lpD = data.lpD;
			while (--iCount >= 0)
				*lpD++ = -1;				
			data.ymin = min(data.y1, data.y2);
			data.ymax = max(data.y1, data.y2);
			data.xmin = min(data.x1, data.x2);
			data.xmax = max(data.x1, data.x2);
			data.ea = dx/2;
			data.eb = dy/2;
			if (!data.ea || !data.eb)
			{
				FreeUp((LPTR)data.lpD);
				return(FALSE);
			}
			asqrd = data.ea*data.ea;
			bsqrd = data.eb*data.eb;

			// fill in a table with radius information for the
			// ellipse.  The radius for a given point would be
			// starting from the center of the ellipse, going 
			// through to point, and where it intersects the 
			// edge of the ellipse.  We need the radius for
			// the D value used in the ellipse_proc, which is
			// the maximum distance used for determining how to
			// calculate the gradient, which is d/D.  d is the 
			// distance of the point from the center, D is extracted
			// from the table built below.  The index of the table is
			// formed from the ratio of sides of the triangle formed.
			// This is like looking up the angle to see where the
			// point would intersect the circle.  But we calculate
			// the radii ahead of time to speed things up.
			if (data.ea > data.eb)	// step in x
			{
				xs = data.xc - data.xc;
				xe = data.xmax - data.xc;
				for (x = xs; x <= xe; ++x)
				{
					y = ((data.eb*(long)lsqrt(asqrd - (x*x)))+(data.ea/2))/data.ea;
					r = (x*x)+(y*y);
					if (r <= 0)
						r = 1;
					index = ((x * x * (long)TSIZE)+(r/2)) / r;
					index = bound(abs(index), 0, TSIZE);
					data.lpD[index] = lsqrt(r);
				}
			}
			else		// step in y
			{
				ys = data.yc - data.yc;
				ye = data.ymax - data.yc;
				for (y = ys; y <= ye; ++y)
				{
					x = ((data.ea*(long)lsqrt(bsqrd - (y*y)))+(data.eb/2))/data.eb;
					r = (x*x)+(y*y);
					if (r <= 0)
						r = 1;
					index = ((y * y * (long)TSIZE)+(r/2)) / r;
					index = bound(abs(index), 0, TSIZE);
					data.lpD[index] = lsqrt(r);
				}
			}
			// find the first valid entry in our table
			for (index = 0; index <= TSIZE && data.lpD[index] < 0; ++index)
				;

			// see if we have any entries
			if (index > TSIZE)
			{
				FreeUp((LPTR)data.lpD);
				return(FALSE);
			}

			// fill in all entries before first with value of first
			while (--index >= 0)
				data.lpD[index] = data.lpD[index+1];

			// find last valid entry in table
			for (index = TSIZE; index >= 0 && data.lpD[index] < 0; --index)
				;

			// see if we have any entries
			if (index < 0)
			{
				FreeUp((LPTR)data.lpD);
				return(FALSE);
			}

			// fill in all entries after last with value of last
			while (++index <= TSIZE)
				data.lpD[index] = data.lpD[index-1];

			// interpolate values of all empty cells
			for (index = 0; index <= TSIZE; ++index)
			{
				if (data.lpD[index] < 0)
				{
					pi = index - 1;
					prev = data.lpD[pi];
					ni = index;
					while (data.lpD[ni] < 0)
						++ni;
					next = data.lpD[ni];
					// remember here that (index-pi) == 1
					data.lpD[index] = prev + ((next-prev)/(ni-pi));
				}
			}
			lpVignetteProc = (LPDATAPROC)ellipse_vignette_proc;
		break;

		default:
			return(FALSE);
		break;
	}

	switch(TypeInfo.DataType)
	{
		case FDT_LINEART :
		case FDT_GRAYSCALE :
			data.lpProcessProc = (LPVIGPROC)ProcessVignette8;
		break;

		case FDT_PALETTECOLOR:
			data.lpProcessProc = (LPVIGPROC)ProcessVignette8P;
			data.lpPaletteLUT = CreatePaletteLut15(TypeInfo.ColorMap->RGBData,
					TypeInfo.ColorMap->NumEntries, NULL, NULL);
		break;

		case FDT_RGBCOLOR :
			data.lpProcessProc = (LPVIGPROC)ProcessVignette24;
		break;

		case FDT_CMYKCOLOR :
			data.lpProcessProc = (LPVIGPROC)ProcessVignette32;
		break;
	}

	data.lpMidpointTable = BuildMidPointTable(
							DoHSL,
							TypeInfo.DataType,
							lpParms->Midpoint,
							&lpParms->StartColor,
							&lpParms->EndColor,
							&data );

	ImgGetMaskRect( lpImage, &rMask );
	data.lplD = (LPLONG)Alloc((long)sizeof(long)*(long)RectWidth(&rMask));
	data.lpld = (LPLONG)Alloc((long)sizeof(long)*(long)RectWidth(&rMask));

	if (!data.lpld || !data.lplD || !data.lpMidpointTable ||
		(TypeInfo.DataType == FDT_PALETTECOLOR && !data.lpPaletteLUT))
	{
		if (lpParms->Gradient == IDC_VIGELLIPSE)
			FreeUp((LPTR)data.lpD);
		if (data.lplD)
			FreeUp((LPTR)data.lplD);
		if (data.lpld)
			FreeUp((LPTR)data.lpld);
		if (data.lpMidpointTable)
			FreeUp((LPTR)data.lpMidpointTable);
		if (data.lpPaletteLUT)
			FreeUp(data.lpPaletteLUT);
		return(FALSE);
	}

	SetEngineDraw(&Engine,lpVignetteProc,lpParms->VigOpacity,lpParms->VigMergeMode);
	Engine.lpParam = &data;
	Engine.fThread = NO;
	lpParms->Common.StatusCode = LineEngineSelObj(lpImage,&Engine,lpParms->Common.idDirty);
	if (!AstralIsRectEmpty(&Engine.rUpdate))
	{
		lpParms->Common.UpdateType = UT_AREA;
		lpParms->Common.rUpdateArea = Engine.rUpdate;
	}

	FreeUp((LPTR)data.lpld);
	FreeUp((LPTR)data.lplD);
	FreeUp((LPTR)data.lpMidpointTable);
	if (data.lpPaletteLUT)
		FreeUp(data.lpPaletteLUT);

	if (lpParms->Gradient == IDC_VIGELLIPSE)
		FreeUp((LPTR)data.lpD);
	return(lpParms->Common.StatusCode == SC_SUCCESS);
}