void ABrainNormalInteractiveObject::Tick(float deltaTime) { Super::Tick(deltaTime); if (_canBeRotate) { _currentRotation += (_deltaRotation * (deltaTime / _animDuration)); _durationRotation += deltaTime; if (_durationRotation > _animDuration) { _currentRotation = _targetRotation; _deltaRotation = FRotator(0, 0, 0); // Annulation du deltaRotation } SetActorRotation(_currentRotation); } if (_canBeTranslate) { _currentTranslation += (_deltaTranslation * deltaTime / _animDuration); _durationTranslation += deltaTime; if (_durationTranslation > _animDuration) { _currentTranslation = _targetTranslation; _deltaTranslation = FVector(0, 0, 0); // Annulation du deltaSize } SetActorLocation(_currentTranslation,true); } if (_canBeScale) { _currentScale += (_deltaScale * deltaTime / _animDuration); _durationScale += deltaTime; if (_durationScale > _animDuration) { _currentScale = _targetScale; _deltaScale = FVector(0,0,0); // Annulation du deltaSize } SetActorScale3D(_currentScale); } if (_canBeShear) { _currentShearFirstAxis += (_deltaShearFirstAxis * deltaTime / _animDuration); _currentShearSecondAxis += (_deltaShearSecondAxis * deltaTime / _animDuration); _durationShear += deltaTime; if (_durationShear > _animDuration) { _currentShearFirstAxis = _targetShearFirstAxis; _currentShearSecondAxis = _targetShearSecondAxis; _deltaShearFirstAxis = 0; _deltaShearSecondAxis = 0; } FTransform sTrans = FTransform(Shear(_currentShearFirstAxis, _currentShearSecondAxis)); SetActorTransform(sTrans*_cachedTransform); } }
status_t FFont::Flatten(void *buffer, ssize_t size) const { if( size < sizeof(flat_font_data) ) return B_BAD_VALUE; // Easy reference to the buffer. flat_font_data* fdat = (flat_font_data*)buffer; memset(fdat,0,sizeof(*fdat)); // Stash away name of family and style. GetFamilyAndStyle(&fdat->family,&fdat->style); // This is used as a temporary when byte-swapping floats. // Note that we are assuming a float is 4 bytes. union { uint32 aslong; float asfloat; } swap; // Byte-swap size, shear, and rotation into the flattened // structure. This is written for clarity more than speed, // since the additional overhead will be entirely subsumed // by everything else going on. swap.asfloat = Size(); swap.aslong = htonl(swap.aslong); fdat->size = swap.asfloat; swap.asfloat = Shear(); swap.aslong = htonl(swap.aslong); fdat->shear = swap.asfloat; swap.asfloat = Rotation(); swap.aslong = htonl(swap.aslong); fdat->rotation = swap.asfloat; // Byte-swap the remaining data into the flattened structure. fdat->flags = htonl(Flags()); fdat->face = htons(Face()); fdat->spacing = Spacing(); fdat->encoding = Encoding(); fdat->mask = htonl(Mask()); return B_NO_ERROR; }
void ABrainNormalInteractiveObject::Load() { FString name = GetName(); FBrainNIOSaveData savedData = Cast<UBrainGameInstance>(GetGameInstance())->GetSaveManager()->GetDataFromSave<FBrainNIOSaveData>(name); if (savedData._loadFromfile) { // Load Translation SetActorLocation(savedData._location); _currentTranslation = savedData._location; _targetTranslation = savedData._location; SetActorRotation(savedData._rotation); _currentRotation = savedData._rotation; _targetRotation = savedData._rotation; SetActorScale3D(savedData._scale); _currentScale = savedData._scale; _targetScale = savedData._scale; _cachedTransform = GetTransform(); SetActorTransform(FTransform(Shear(savedData._shearFirstAxis, savedData._shearSecondAxis))*_cachedTransform); } }
void ABrainNormalInteractiveObject::Load() { if (!GetName().IsEmpty()) { if (UBrainGameInstance* gameInstance = Cast<UBrainGameInstance>(GetGameInstance())) { if (UBrainSaveManager* saveManager = gameInstance->GetSaveManager()) { FBrainNIOSaveData savedData = saveManager->GetDataFromSave<FBrainNIOSaveData>(GetName()); if (savedData._loadFromfile) { // Movement Counters and Energy _countRotation = savedData._countRotation; _countTranslation = savedData._countTranslation; _countScale = savedData._countScale; _countShear = savedData._countShear; // Load Translation SetActorLocation(savedData._location); _currentTranslation = savedData._location; _targetTranslation = savedData._location; SetActorRotation(savedData._rotation); _currentRotation = savedData._rotation; _targetRotation = savedData._rotation; SetActorScale3D(savedData._scale); _currentScale = savedData._scale; _targetScale = savedData._scale; _cachedTransform = GetTransform(); SetActorTransform(FTransform(Shear(savedData._shearFirstAxis, savedData._shearSecondAxis)) * _cachedTransform); } } } } }
void FFont::UpdateTo(BFont* font, uint32 mask) const { if( !font ) return; mask &= attrMask; if( (mask&B_FONT_ALL) == B_FONT_ALL ) { // Quickly copy everything. *font = *(BFont*)this; return; } // Only copy specific fields. if( mask & B_FONT_FAMILY_AND_STYLE ) { font->SetFamilyAndStyle(FamilyAndStyle()); } if( mask & B_FONT_SIZE ) { font->SetSize(Size()); } if( mask & B_FONT_SHEAR ) { font->SetShear(Shear()); } if( mask & B_FONT_ROTATION ) { font->SetRotation(Rotation()); } if( mask & B_FONT_SPACING ) { font->SetSpacing(Spacing()); } if( mask & B_FONT_ENCODING ) { font->SetEncoding(Encoding()); } if( mask & B_FONT_FACE ) { font->SetFace(Face()); } if( mask & B_FONT_FLAGS ) { font->SetFlags(Flags()); } }
bool CTrack::Move(int x, int y) { if (m_bDisabled) return false; if (!m_iHandleGrabbed) return false; // Prevent any accidental moves on the first click if (m_iHandleGrabbed == H_MOVE && !m_bMoved) { #define CLOSENESS 10 // pixels int dx = m_iLastDownX - x; int dy = m_iLastDownY - y; if (dx >= -CLOSENESS && dx <= CLOSENESS && dy >= -CLOSENESS && dy <= CLOSENESS) return false; } if (m_bShear) ConstrainXY(&x, &y, true/*bButtonDown*/, false/*bInit*/, m_bShear/*bActive*/); x = bound(x, m_BoundRectScreen.left, m_BoundRectScreen.right); y = bound(y, m_BoundRectScreen.top, m_BoundRectScreen.bottom); CPoint pt(x, y); m_ViewToDeviceMatrix.Inverse().Transform(pt); x = pt.x; y = pt.y; if (x == m_iLastX && y == m_iLastY) return false; m_bMoved = true; Draw(false/*bOn*/); switch (m_iHandleGrabbed) { case H_UL: { m_Grid.Snap(pt); m_bMoveOnly = false; if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE)) Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/); if (m_bShear) Shear(pt.x, pt.y, m_Distort.Rect.left, m_Distort.Rect.top, m_bConstrainX, m_bConstrainY); else Scale(pt.x, pt.y, m_Distort.Rect.left, m_Distort.Rect.top, m_Distort.Rect.right, m_Distort.Rect.bottom, m_bConstrainAspect ^ CONTROL); break; } case H_UR: { m_Grid.Snap(pt); m_bMoveOnly = false; if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE)) Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/); if (m_bShear) Shear(pt.x, pt.y, m_Distort.Rect.right, m_Distort.Rect.top, m_bConstrainX, m_bConstrainY); else Scale(pt.x, pt.y, m_Distort.Rect.right, m_Distort.Rect.top, m_Distort.Rect.left, m_Distort.Rect.bottom, m_bConstrainAspect ^ CONTROL); break; } case H_LR: { m_Grid.Snap(pt); m_bMoveOnly = false; if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE)) Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/); if (m_bShear) Shear(pt.x, pt.y, m_Distort.Rect.right, m_Distort.Rect.bottom, m_bConstrainX, m_bConstrainY); else Scale(pt.x, pt.y, m_Distort.Rect.right, m_Distort.Rect.bottom, m_Distort.Rect.left, m_Distort.Rect.top, m_bConstrainAspect ^ CONTROL); break; } case H_LL: { m_Grid.Snap(pt); m_bMoveOnly = false; if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE)) Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/); if (m_bShear) Shear(pt.x, pt.y, m_Distort.Rect.left, m_Distort.Rect.bottom, m_bConstrainX, m_bConstrainY); else Scale(pt.x, pt.y, m_Distort.Rect.left, m_Distort.Rect.bottom, m_Distort.Rect.right, m_Distort.Rect.top, m_bConstrainAspect ^ CONTROL); break; } case H_TOP: { m_Grid.Snap(pt); m_bMoveOnly = false; if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE)) Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/); int midx = (m_Distort.Rect.left + m_Distort.Rect.right)/2; if (m_bShear) Shear(pt.x, pt.y, midx, m_Distort.Rect.top, m_bConstrainX, m_bConstrainY); else { CPoint ptMid(midx, m_Distort.Rect.top); long dummy; m_Matrix.Transform(ptMid, pt.x, dummy); Scale(pt.x, pt.y, midx, m_Distort.Rect.top, midx, m_Distort.Rect.bottom, false/*bConstrainAspect*/); } break; } case H_RIGHT: { m_Grid.Snap(pt); m_bMoveOnly = false; if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE)) Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/); int midy = (m_Distort.Rect.top + m_Distort.Rect.bottom)/2; if (m_bShear) Shear(pt.x, pt.y, m_Distort.Rect.right, midy, m_bConstrainX, m_bConstrainY); else { CPoint ptMid(m_Distort.Rect.right, midy); long dummy; m_Matrix.Transform(ptMid, dummy, pt.y); Scale(pt.x, pt.y, m_Distort.Rect.right, midy, m_Distort.Rect.left, midy, false/*bConstrainAspect*/); } break; } case H_BOTTOM: { m_Grid.Snap(pt); m_bMoveOnly = false; if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE)) Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/); int midx = (m_Distort.Rect.left + m_Distort.Rect.right)/2; if (m_bShear) Shear(pt.x, pt.y, midx, m_Distort.Rect.bottom, m_bConstrainX, m_bConstrainY); else { CPoint ptMid(midx, m_Distort.Rect.bottom); long dummy; m_Matrix.Transform(ptMid, pt.x, dummy); Scale(pt.x, pt.y, midx, m_Distort.Rect.bottom, midx, m_Distort.Rect.top, false/*bConstrainAspect*/); } break; } case H_LEFT: { m_Grid.Snap(pt); m_bMoveOnly = false; if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE)) Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/); int midy = (m_Distort.Rect.top + m_Distort.Rect.bottom)/2; if (m_bShear) Shear(pt.x, pt.y, m_Distort.Rect.left, midy, m_bConstrainX, m_bConstrainY); else { CPoint ptMid(m_Distort.Rect.left, midy); long dummy; m_Matrix.Transform(ptMid, dummy, pt.y); Scale(pt.x, pt.y, m_Distort.Rect.left, midy, m_Distort.Rect.right, midy, false/*bConstrainAspect*/); } break; } case H_CENTER: { // transform points to transformed position m_Matrix.Transform(m_ptCenter); m_Matrix.Transform(m_ptRotate); int dx = pt.x - m_ptCenter.x; int dy = pt.y - m_ptCenter.y; m_ptRotate.x += dx; m_ptRotate.y += dy; m_ptCenter = pt; // transform points back to untransformed position m_Matrix.Inverse().Transform(m_ptCenter); m_Matrix.Inverse().Transform(m_ptRotate); break; } case H_CORNER_UL: case H_CORNER_UR: case H_CORNER_LR: case H_CORNER_LL: { m_Grid.Snap(pt); m_bMoveOnly = false; if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE)) Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/); // transform the new point back to its untransformed position CPoint ptTemp = pt; m_Matrix.Inverse().Transform(ptTemp); int i = m_iHandleGrabbed - H_CORNER_UL; m_Distort.p[i] = ptTemp; // Update the m_Distort.Rect rectangle m_Distort.Rect.left = min(min(min(m_Distort.p[0].x, m_Distort.p[1].x), m_Distort.p[2].x), m_Distort.p[3].x); m_Distort.Rect.right = max(max(max(m_Distort.p[0].x, m_Distort.p[1].x), m_Distort.p[2].x), m_Distort.p[3].x); m_Distort.Rect.top = min(min(min(m_Distort.p[0].y, m_Distort.p[1].y), m_Distort.p[2].y), m_Distort.p[3].y); m_Distort.Rect.bottom = max(max(max(m_Distort.p[0].y, m_Distort.p[1].y), m_Distort.p[2].y), m_Distort.p[3].y); break; } case H_ROTATE: { m_bMoveOnly = false; if (m_bExclusive && (m_iWhatCanDo & TR_SIZE)) Mode(m_iWhatCanDo & ~TR_SIZE, false/*fDisplay*/); // transform points to transformed position Rotate(pt.x, pt.y, m_iStartRotateX, m_iStartRotateY); m_ptRotate = pt; // transform points back to untransformed position m_Matrix.Inverse().Transform(m_ptRotate); break; } case H_MOVE: { // Calculate how far we SHOULD move CPoint delta1(pt.x - m_iLastX, pt.y - m_iLastY); // Calculate where we are right now CRect rect = m_Distort.Rect; m_Matrix.Transform(rect); // Calculate the new top-left point CPoint ptNewTL(rect.left + delta1.x, rect.top + delta1.y); // Snap it to the grid m_Grid.Snap(ptNewTL); if (m_iWhatCanDo & TR_BOUNDTOSYMBOL) { int delta; delta = ptNewTL.x - m_BoundRect.left; if (delta < 0) ptNewTL.x -= delta; delta = ptNewTL.y - m_BoundRect.top; if (delta < 0) ptNewTL.y -= delta; delta = (ptNewTL.x + rect.Width()) - m_BoundRect.right; if (delta > 0) ptNewTL.x -= delta; delta = (ptNewTL.y + rect.Height()) - m_BoundRect.bottom; if (delta > 0) ptNewTL.y -= delta; } // Calculate how far we WILL move CPoint delta2(ptNewTL.x - rect.left, ptNewTL.y - rect.top); // Adjust the point for the next time around x -= (delta1.x - delta2.x); y -= (delta1.y - delta2.y); m_Matrix.Translate(delta2.x, delta2.y); break; } default: return false; } if (m_pDrawProc && m_pAGDC) { HDC hDC = m_pAGDC->GetHDC(); m_pDrawProc(hDC, false/*bOn*/, TOOLCODE_UPDATE, m_pData); } Draw(true/*bOn*/); m_iLastX = x; m_iLastY = y; return true; }
/// <summary> Sets this matrix to a shear matrix. </summary> /// <param name="slope"> Strength of the shear. </param> /// <param name="principalAxis"> Points are moved along this axis. </param> /// <param name="modulatorAxis"> The displacement of points is proportional to this coordinate's value. </param> /// <remarks> The formula for displacement along the pricipal axis is /// <paramref name="slope"/>*pos[<paramref name="modulatorAxis"/>]. </remarks> MatrixT& SetShear(T slope, int principalAxis, int modulatorAxis) { self() = Shear(slope, principalAxis, modulatorAxis); return self(); }
/* Routine to build a projective transform from input text, display, or write transformed image to a file */ void process_input(Matrix3x3 &M) { char command[1024]; bool done; float theta; float inputX; float inputY; float inputZ; /* build identity matrix */ M.identity(); for(done = false; !done;) { /* prompt and accept input, converting text to lower case */ printf("> "); scanf("%s", command); lowercase(command); /* parse the input command, and read parameters as needed */ if(strcmp(command, "d") == 0) { done = true; } else if(strlen(command) != 1) { printf("invalid command, enter r, s, t, h, d\n"); } else { switch(command[0]) { case 'r': /* Rotation, accept angle in degrees */ if(scanf("%f", &theta) == 1) Rotate(M, theta); else fprintf(stderr, "invalid rotation angle\n"); break; case 's': /* Scale, accept scale factors */ if(scanf("%f %f", &inputX, &inputY)) Scale(M, inputX, inputY); else fprintf(stderr,"invalid scaling input\n"); break; case 't': /* Translation, accept translations */ if(scanf("%f %f", &inputX, &inputY)) Translate(M, inputX, inputY); else fprintf(stderr,"invalid scaling input\n"); break; case 'h': /* Shear, accept shear factors */ if(scanf("%f %f", &inputX, &inputY)) Shear(M, inputX, inputY); else fprintf(stderr,"invalid scaling input\n"); break; //twirl mode on case 'n': if(scanf("%f %f %f", &inputX, &inputY, &inputZ)) { manager.turnTwrilModeOn(inputX, inputY, inputZ); } else { fprintf(stderr, "invalid scaling input\n"); } break; case 'p': if(scanf("%f %f", &inputX, &inputY)) Perspective(M, inputX, inputY); else fprintf(stderr,"invalid scaling input\n"); break; case 'd': /* Done, that's all for now */ done = true; break; default: printf("invalid command, enter r, s, t, h, d\n"); } } } }