本文整理汇总了C++中Rotate函数的典型用法代码示例。如果您正苦于以下问题:C++ Rotate函数的具体用法?C++ Rotate怎么用?C++ Rotate使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Rotate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TurnOnRight
//Fonction TurnOnRight-------------------------------------------------------------faux
void TurnOnRight(int delay)
{
OCR1A = RIGHT; //on change la fréquence de découpage du timer pour que l'interprétation faite par lesecond ATMEGA fasse que le gouvernail tourne à droite
Rotate(delay);
}
示例2: clearChildren
void RotatedComponent::changed(ConstFieldMaskArg whichField,
UInt32 origin,
BitVector details)
{
Inherited::changed(whichField, origin, details);
//Do not respond to changes that have a Sync origin
if(origin & ChangedOrigin::Sync)
{
return;
}
if(whichField & InternalComponentFieldMask)
{
clearChildren();
if(getInternalComponent() != NULL)
{
pushToChildren(getInternalComponent());
}
}
if((whichField & InternalComponentFieldMask) ||
(whichField & AngleFieldMask) ||
(whichField & ResizePolicyFieldMask))
{
if(getInternalComponent() != NULL)
{
Vec2f Size;
switch (static_cast<ResizePolicy>(getResizePolicy()))
{
case RESIZE_TO_MIN:
{
//Treat TopLeft as 0,0
//Get the Rotated Bounds of the Internal Component
Pnt2f p1,p2,p3,p4;
Pnt2f ComponentCenter(static_cast<Real32>(getInternalComponent()->getSize().x())/2.0, static_cast<Real32>(getInternalComponent()->getSize().y())/2.0);
p1 = -ComponentCenter;
p2.setValues(ComponentCenter.x(),-ComponentCenter.y());
p3 = ComponentCenter;
p4.setValues(-ComponentCenter.x(),ComponentCenter.y());
//Rotate them
p1 = Rotate(p1, -getAngle());
p2 = Rotate(p2, -getAngle());
p3 = Rotate(p3, -getAngle());
p4 = Rotate(p4, -getAngle());
//Get their min and max
Pnt2f Min(osgMin(osgMin(osgMin(p1.x(),p2.x()),p3.x()),p4.x()),
osgMin(osgMin(osgMin(p1.y(),p2.y()),p3.y()),p4.y()));
Pnt2f Max(osgMax(osgMax(osgMax(p1.x(),p2.x()),p3.x()),p4.x()),
osgMax(osgMax(osgMax(p1.y(),p2.y()),p3.y()),p4.y()));
Pnt2f BorderTopLeft, BorderBottomRight;
getInsideInsetsBounds(BorderTopLeft, BorderBottomRight);
Pnt2f TopLeft, BottomRight;
getBounds(TopLeft, BottomRight);
setPreferredSize(Vec2f(Max.x() - Min.x() + (BorderTopLeft.x() - TopLeft.x()) + (BottomRight.x() - BorderBottomRight.x()),
Max.y() - Min.y() + (BorderTopLeft.y() - TopLeft.y()) + (BottomRight.y() - BorderBottomRight.y())));
break;
}
case RESIZE_TO_MAX:
{
//Get the Internal Components Center
Pnt2f ComponentCenter(static_cast<Real32>(getInternalComponent()->getSize().x())/2.0, static_cast<Real32>(getInternalComponent()->getSize().y())/2.0);
//Get the distance from the Center to one of the TopLeft Corner
Real32 Length = 2*ComponentCenter.dist(Pnt2f(0,0));
setPreferredSize(Vec2f(Length,Length));
break;
}
case NO_RESIZING:
default:
break;
}
getInternalComponent()->updateClipBounds();
//Check the Mouse
if( getParentWindow() != NULL &&
getParentWindow()->getParentDrawingSurface() != NULL &&
getParentWindow()->getParentDrawingSurface()->getEventProducer() != NULL)
{
Pnt2f MouseLoc(getParentWindow()->getParentDrawingSurface()->getEventProducer()->getMousePosition());
MouseEventDetailsUnrecPtr e = MouseEventDetails::create(getParentWindow()->getParentDrawingSurface()->getEventProducer(),getSystemTime(),MouseEventDetails::NO_BUTTON,0,MouseLoc, NULL);
checkMouseEnterExit(e,e->getLocation(),getInternalComponent(),getInternalComponent()->isContained(MouseLoc, true),e->getViewport());
}
}
}
}
示例3: Translate
void Asteroid::tick(double DT)
{
Translate((motionProperties.speed * motionProperties.direction) * static_cast<float>(DT));
Rotate(motionProperties.angularSpeed * static_cast<float>(DT) * motionProperties.rotation);
}
示例4: Rotation
void Matrix::Rotate(double angle, int Axis)
{ // Rotation (Axis 1 = x , 2 = y , 3 = z
Rotate(sin(angle), cos(angle), Axis);
}
示例5: SINGLETONINSTANCE
//.........这里部分代码省略.........
tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE);
box1->model = SINGLETONINSTANCE( MediaManager )->boxModel;
box1->physicsModel = tempStaticObject;
box1->physicsModel->InitializeAsRectangle(physicsBox);
SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject);
box1->SetPos2D(20.0f, 40.0f);
box1->SetScale(40.0f, 1.0f, 3.0f);
auto box2 = new Object();
box2->Name = "Box2";
box2->model = SINGLETONINSTANCE( MediaManager )->boxModel;
tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE);
box2->physicsModel = tempStaticObject;
box2->physicsModel->InitializeAsRectangle(physicsBox);
SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject);
box2->SetPos2D(0.0f, 20.0f);
box2->SetScale(1.0f, 40.0f, 3.0f);
auto box3 = new Object();
box3->Name = "Box3";
box3->model = SINGLETONINSTANCE( MediaManager )->boxModel;
tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE);
box3->physicsModel = tempStaticObject;
box3->physicsModel->InitializeAsRectangle(physicsBox);
SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject);
box3->SetPos2D(40.0f, 20.0f);
box3->SetScale(1.0f, 40.0f, 3.0f);
auto box4 = new Object();
box4->Name = "Box4";
box4->model = SINGLETONINSTANCE( MediaManager )->boxModel;
tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE);
box4->physicsModel = tempStaticObject;
box4->physicsModel->InitializeAsRectangle(physicsBox);
SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject);
box4->SetPos2D(27.0f, 15.0f);
box4->SetScale(1.0f, 30.0f, 3.0f);
auto box5 = new Object();
box5->Name = "Box5";
box5->model = SINGLETONINSTANCE( MediaManager )->boxModel;
tempStaticObject = new StaticObjectModel(RECTANGULARSHAPE);
box5->physicsModel = tempStaticObject;
box5->physicsModel->InitializeAsRectangle(physicsBox);
SINGLETONINSTANCE(PhysicsSystem)->AddStaticObject(tempStaticObject);
box5->SetPos2D(13.0f, 25.0f);
box5->SetScale(1.0f, 30.0f, 3.0f);
root->children->push_back(*underground);
root->children->push_back(*ground);
root->children->push_back(*box);
root->children->push_back(*box1);
root->children->push_back(*box2);
root->children->push_back(*box3);
root->children->push_back(*box4);
root->children->push_back(*box5);
SINGLETONINSTANCE(PhysicsSystem)->SetStaticPathMap();
Point forward;
forward.X = 0;
forward.Y = -1;
forward = forward.GetNormalizedPoint();
auto player = new Object();
SINGLETONINSTANCE(PlayerInteraction)->StartUp(player);
player->Name = "Player";
player->model = SINGLETONINSTANCE( MediaManager )->crazyModel;
MovingObjectModel* tempMovingObject = new MovingObjectModel(CIRCULARSHAPE, PLAYERTYPE, forward, player);
player->physicsModel = tempMovingObject;
Circle circle(Point(0.0f,0.0f),0.5f);
player->physicsModel->InitializeAsCircle(circle);
SINGLETONINSTANCE(PhysicsSystem)->AddMovingObject(tempMovingObject);
player->SetPos2D(15,20);
player->Rotate(90.0f, 1.0f, 0.0f, 0.0f);
player->SetForward(0.0f, 1.0f);
player->setLookAt2D(forward.X,forward.Y);
root->children->push_back(*player);
player->physicsModel->SetTargetPosition(new Point(50,5));
auto camera = new Camera();
camera->Position.SetX(20);
camera->Position.SetY(5);
camera->Position.SetZ(50);
camera->LookAt.SetX(20);
camera->LookAt.SetY(20);
camera->LookAt.SetZ(-1);
camera->Up.SetX(0);
camera->Up.SetY(1);
camera->Up.SetZ(0);
SceneGraphManager *sceneGraph = new SceneGraphManager(camera, root);
return sceneGraph;
}
示例6: Rotate
void HawkTransform::Rotate(HawkRect2D& oRect,const HawkVector2D& oRefPt,const HawkRadian& oRad)
{
Rotate(oRect.Point,oRefPt,oRad);
Rotate(oRect.Edge[0],HawkVector2D(0,0),oRad);
Rotate(oRect.Edge[1],HawkVector2D(0,0),oRad);
}
示例7: RotateRel
inline void RotateRel(const float RAngle, const float NormalX, const float NormalY, const float NormalZ)
{
Rotate(rangle+RAngle, NormalX, NormalY, NormalZ);
}
示例8: Safety_Override
void Safety_Override(void)
{
/*
This function is intended to keep the lander from
crashing. It checks the sonar distance array,
if the distance to nearby solid surfaces and
uses thrusters to maintain a safe distance from
the ground unless the ground happens to be the
landing platform.
Additionally, it enforces a maximum speed limit
which when breached triggers an emergency brake
operation.
*/
/**************************************************
TO DO: Modify this function so that it can do its
work even if components or sensors
fail
**************************************************/
/**************************************************
How this works:
Check the sonar readings, for each sonar
reading that is below a minimum safety threshold
AND in the general direction of motion AND
not corresponding to the landing platform,
carry out speed corrections using the thrusters
**************************************************/
double DistLimit;
double Vmag;
double dmin;
// Establish distance threshold based on lander
// speed (we need more time to rectify direction
// at high speed)
Vmag=Velocity_X()*Velocity_X();
Vmag+=Velocity_Y()*Velocity_Y();
DistLimit=fmax(75,Vmag);
// If we're close to the landing platform, disable
// safety override (close to the landing platform
// the Control_Policy() should be trusted to
// safely land the craft)
if (fabs(PLAT_X-Position_X())<150&&fabs(PLAT_Y-Position_Y())<150) return;
// Determine the closest surfaces in the direction
// of motion. This is done by checking the sonar
// array in the quadrant corresponding to the
// ship's motion direction to find the entry
// with the smallest registered distance
// Horizontal direction.
dmin=1000000;
if (Velocity_X()>0)
{
for (int i=5;i<14;i++)
if (SONAR_DIST[i]>-1&&SONAR_DIST[i]<dmin) dmin=SONAR_DIST[i];
}
else
{
for (int i=22;i<32;i++)
if (SONAR_DIST[i]>-1&&SONAR_DIST[i]<dmin) dmin=SONAR_DIST[i];
}
// Determine whether we're too close for comfort. There is a reason
// to have this distance limit modulated by horizontal speed...
// what is it?
if (dmin<DistLimit*fmax(.25,fmin(fabs(Velocity_X())/5.0,1)))
{ // Too close to a surface in the horizontal direction
if (Angle()>1&&Angle()<359)
{
if (Angle()>=180) Rotate(360-Angle());
else Rotate(-Angle());
return;
}
if (Velocity_X()>0){
Right_Thruster(1.0);
Left_Thruster(0.0);
}
else
{
Left_Thruster(1.0);
Right_Thruster(0.0);
}
}
// Vertical direction
dmin=1000000;
if (Velocity_Y()>5) // Mind this! there is a reason for it...
{
for (int i=0; i<5; i++)
if (SONAR_DIST[i]>-1&&SONAR_DIST[i]<dmin) dmin=SONAR_DIST[i];
for (int i=32; i<36; i++)
if (SONAR_DIST[i]>-1&&SONAR_DIST[i]<dmin) dmin=SONAR_DIST[i];
}
else
{
//.........这里部分代码省略.........
示例9: memcpy
//.........这里部分代码省略.........
}
else if (missionLoadType == MISSION_LOAD_SP_LOGISTICS) {
EList< LogisticsMech*, LogisticsMech* > list;
LogisticsData::instance->getForceGroup( list );
float rotation = list.Count() ? 360.f/list.Count() : 0.f;
MoverInitData data;
memset( &data, 0, sizeof( data ) );
data.rosterIndex = 255;
data.controlType = 2;
data.controlDataType = 1;
data.position.Zero(); // need to get the drop zone location
data.rotation = 0;
data.teamID = Team::home->getId();
data.commanderID = Team::home->getId();
data.active = 1;
data.exists = 1;
data.capturable = 0;
data.baseColor = prefs.baseColor;
data.highlightColor1 = prefs.highlightColor;
data.highlightColor2 = prefs.highlightColor;
strcpy( data.pilotFileName, "pmw00031" );
strcpy( data.brainFileName, "pbrain" );
Stuff::Vector3D vector;
vector.x = 0.f;
vector.y = 1.f;
vector.z = 0.f;
Stuff::Vector3D scaled;
for ( EList< LogisticsMech*, LogisticsMech* >::EIterator iter = list.Begin(); !iter.IsDone(); iter++) {
scaled = vector;
scaled *= 128.;
data.position.Add(dropZoneList[0], scaled);
//data.position = dropZoneList[dropZoneIndex++];
data.objNumber = (*iter)->getFitID();
strcpy( data.csvFileName, (*iter)->getFileName() );
if ( !(*iter)->getPilot() )
continue;
strcpy( data.pilotFileName, (*iter)->getPilot()->getFileName() );
data.overrideLoadedPilot = true;
data.gunnerySkill = (*iter)->getPilot()->getGunnery();
data.pilotingSkill = (*iter)->getPilot()->getPiloting();
memcpy(data.specialtySkills,(*iter)->getPilot()->getSpecialtySkills(),sizeof(bool) * NUM_SPECIALTY_SKILLS);
if ( !(*iter)->getVariant()->isDesignerMech())
{
data.variant = 0;
mission->addMover( &data, (*iter));
}
else
{
data.variant = (*iter)->getVariant()->getFileID();
mission->addMover( &data );
}
Rotate( vector, rotation );
}
}
/* if (MPlayer) {
if (MPlayer->isHost())
MPlayer->serverCID = MPlayer->commanderID;
else {
for (long i = 0; i < MAX_MC_PLAYERS; i++)
if (MPlayer->serverPlayer && (MPlayer->playerList[i].player == MPlayer->serverPlayer))
MPlayer->serverCID = MPlayer->playerList[i].commanderID;
if (MPlayer->serverCID == -1)
STOP(("Logistics.beginMission: bad serverCID"));
}
}
*/
mission->missionInterface->initMechs();
eye->activate();
eye->update();
mission->start();
mission->update(); // force this, so we don't render first
if (MPlayer) {
CompressedMech mechData;
mechData.commanderID = MPlayer->commanderID;
MPlayer->sendMissionSetup(0, 4, &mechData);
if (!MPlayer->waitTillMissionSetup()) {
// SERVER DROPPED
mission->destroy();
return(0);
}
MPlayer->setMode(MULTIPLAYER_MODE_MISSION);
}
if (MPlayer && MPlayer->hostLeft) {
mission->destroy();
return(0);
}
return(1);
}
示例10: Jacobi
void Jacobi(const SymmetricMatrix& X, DiagonalMatrix& D, SymmetricMatrix& A,
Matrix& V, bool eivec)
{
Real epsilon = FloatingPointPrecision::Epsilon();
Tracer et("Jacobi");
REPORT
int n = X.Nrows(); DiagonalMatrix B(n), Z(n); D.resize(n); A = X;
if (eivec) { REPORT V.resize(n,n); D = 1.0; V = D; }
B << A; D = B; Z = 0.0; A.Inject(Z);
bool converged = false;
for (int i=1; i<=50; i++)
{
Real sm=0.0; Real* a = A.Store(); int p = A.Storage();
while (p--) sm += fabs(*a++); // have previously zeroed diags
if (sm==0.0) { REPORT converged = true; break; }
Real tresh = (i<4) ? 0.2 * sm / square(n) : 0.0; a = A.Store();
for (p = 0; p < n; p++)
{
Real* ap1 = a + (p*(p+1))/2;
Real& zp = Z.element(p); Real& dp = D.element(p);
for (int q = p+1; q < n; q++)
{
Real* ap = ap1; Real* aq = a + (q*(q+1))/2;
Real& zq = Z.element(q); Real& dq = D.element(q);
Real& apq = A.element(q,p);
Real g = 100 * fabs(apq); Real adp = fabs(dp); Real adq = fabs(dq);
if (i>4 && g < epsilon*adp && g < epsilon*adq) { REPORT apq = 0.0; }
else if (fabs(apq) > tresh)
{
REPORT
Real t; Real h = dq - dp; Real ah = fabs(h);
if (g < epsilon*ah) { REPORT t = apq / h; }
else
{
REPORT
Real theta = 0.5 * h / apq;
t = 1.0 / ( fabs(theta) + sqrt(1.0 + square(theta)) );
if (theta<0.0) { REPORT t = -t; }
}
Real c = 1.0 / sqrt(1.0 + square(t)); Real s = t * c;
Real tau = s / (1.0 + c); h = t * apq;
zp -= h; zq += h; dp -= h; dq += h; apq = 0.0;
int j = p;
while (j--)
{
g = *ap; h = *aq;
*ap++ = g-s*(h+g*tau); *aq++ = h+s*(g-h*tau);
}
int ip = p+1; j = q-ip; ap += ip++; aq++;
while (j--)
{
g = *ap; h = *aq;
*ap = g-s*(h+g*tau); *aq++ = h+s*(g-h*tau);
ap += ip++;
}
if (q < n-1) // last loop is non-empty
{
int iq = q+1; j = n-iq; ap += ip++; aq += iq++;
for (;;)
{
g = *ap; h = *aq;
*ap = g-s*(h+g*tau); *aq = h+s*(g-h*tau);
if (!(--j)) break;
ap += ip++; aq += iq++;
}
}
if (eivec)
{
REPORT
RectMatrixCol VP(V,p); RectMatrixCol VQ(V,q);
Rotate(VP, VQ, tau, s);
}
}
}
}
B = B + Z; D = B; Z = 0.0;
}
if (!converged) Throw(ConvergenceException(X));
if (eivec) SortSV(D, V, true);
else SortAscending(D);
}
示例11: Lander_Control
void Lander_Control(void)
{
/*
This is the main control function for the lander. It attempts
to bring the ship to the location of the landing platform
keeping landing parameters within the acceptable limits.
How it works:
- First, if the lander is rotated away from zero-degree angle,
rotate lander back onto zero degrees.
- Determine the horizontal distance between the lander and
the platform, fire horizontal thrusters appropriately
to change the horizontal velocity so as to decrease this
distance
- Determine the vertical distance to landing platform, and
allow the lander to descend while keeping the vertical
speed within acceptable bounds. Make sure that the lander
will not hit the ground before it is over the platform!
As noted above, this function assumes everything is working
fine.
*/
/*************************************************
TO DO: Modify this function so that the ship safely
reaches the platform even if components and
sensors fail!
Note that sensors are noisy, even when
working properly.
Finally, YOU SHOULD provide your own
functions to provide sensor readings,
these functions should work even when the
sensors are faulty.
For example: Write a function Velocity_X_robust()
which returns the module's horizontal velocity.
It should determine whether the velocity
sensor readings are accurate, and if not,
use some alternate method to determine the
horizontal velocity of the lander.
NOTE: Your robust sensor functions can only
use the available sensor functions and control
functions!
DO NOT WRITE SENSOR FUNCTIONS THAT DIRECTLY
ACCESS THE SIMULATION STATE. That's cheating,
I'll give you zero.
**************************************************/
double VXlim;
double VYlim;
// Set velocity limits depending on distance to platform.
// If the module is far from the platform allow it to
// move faster, decrease speed limits as the module
// approaches landing. You may need to be more conservative
// with velocity limits when things fail.
if (fabs(Position_X()-PLAT_X)>200) VXlim=25;
else if (fabs(Position_X()-PLAT_X)>100) VXlim=15;
else VXlim=5;
if (PLAT_Y-Position_Y()>200) VYlim=-20;
else if (PLAT_Y-Position_Y()>100) VYlim=-10; // These are negative because they
else VYlim=-4; // limit descent velocity
// Ensure we will be OVER the platform when we land
if (fabs(PLAT_X-Position_X())/fabs(Velocity_X())>1.25*fabs(PLAT_Y-Position_Y())/fabs(Velocity_Y())) VYlim=0;
// IMPORTANT NOTE: The code below assumes all components working
// properly. IT MAY OR MAY NOT BE USEFUL TO YOU when components
// fail. More likely, you will need a set of case-based code
// chunks, each of which works under particular failure conditions.
// Check for rotation away from zero degrees - Rotate first,
// use thrusters only when not rotating to avoid adding
// velocity components along the rotation directions
// Note that only the latest Rotate() command has any
// effect, i.e. the rotation angle does not accumulate
// for successive calls.
if (Angle()>1&&Angle()<359)
{
if (Angle()>=180) Rotate(360-Angle());
else Rotate(-Angle());
return;
}
// Module is oriented properly, check for horizontal position
// and set thrusters appropriately.
if (Position_X()>PLAT_X)
{
// Lander is to the LEFT of the landing platform, use Right thrusters to move
// lander to the left.
Left_Thruster(0); // Make sure we're not fighting ourselves here!
if (Velocity_X()>(-VXlim)) Right_Thruster((VXlim+fmin(0,Velocity_X()))/VXlim);
else
{
//.........这里部分代码省略.........
示例12: getViewControls
//.........这里部分代码省略.........
{
// Set the current cursor position to the first dragged item origin, so the
// movement vector could be computed later
m_cursor = grid.BestDragOrigin( originalCursorPos, item );
grid.SetAuxAxes( true, m_cursor );
}
else
{
m_cursor = grid.Align( m_cursor );
}
controls->ForceCursorPosition( true, m_cursor );
controls->WarpCursor( m_cursor, true );
VECTOR2I o = VECTOR2I( item->GetPosition() );
m_offset.x = o.x - m_cursor.x;
m_offset.y = o.y - m_cursor.y;
controls->SetAutoPan( true );
m_dragging = true;
incUndoInhibit();
}
}
selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true );
}
// Dispatch TOOL_ACTIONs
else if( evt->Category() == TC_COMMAND )
{
if( evt->IsAction( &COMMON_ACTIONS::rotate ) )
{
Rotate( aEvent );
}
else if( evt->IsAction( &COMMON_ACTIONS::flip ) )
{
Flip( aEvent );
// Flip causes change of layers
enableUpdateFlag( KIGFX::VIEW_ITEM::LAYERS );
}
else if( evt->IsAction( &COMMON_ACTIONS::remove ) )
{
Remove( aEvent );
break; // exit the loop, as there is no further processing for removed items
}
else if( evt->IsAction( &COMMON_ACTIONS::duplicate ) )
{
// On duplicate, stop moving this item
// The duplicate tool should then select the new item and start
// a new move procedure
break;
}
else if( evt->IsAction( &COMMON_ACTIONS::moveExact ) )
{
// Can't do this, because the selection will then contain
// stale pointers and it will all go horribly wrong...
//editFrame->RestoreCopyFromUndoList( dummy );
//
// So, instead, reset the position manually
for( unsigned int i = 0; i < selection.items.GetCount(); ++i )
{
BOARD_ITEM* item = selection.Item<BOARD_ITEM>( i );
item->SetPosition( item->GetPosition() - totalMovement );
示例13: Meigen
inline static void Meigen( SWIFT_Real vout[3][3], SWIFT_Real dout[3],
SWIFT_Real a[3][3] )
{
int n = 3;
int j,iq,ip,i;
SWIFT_Real tresh,theta,tau,t,sm,s,h,g,c;
int nrot;
SWIFT_Real b[3];
SWIFT_Real z[3];
SWIFT_Real v[3][3];
SWIFT_Real d[3];
v[0][0] = v[1][1] = v[2][2] = 1.0;
v[0][1] = v[1][2] = v[2][0] = 0.0;
v[0][2] = v[1][0] = v[2][1] = 0.0;
for( ip = 0; ip < n; ip++ ) {
b[ip] = a[ip][ip];
d[ip] = a[ip][ip];
z[ip] = 0.0;
}
nrot = 0;
for( i = 0; i < 50; i++ ) {
sm=0.0;
for( ip = 0;ip < n; ip++ ) {
for( iq = ip+1; iq < n; iq++ ) {
sm += fabs(a[ip][iq]);
}
}
if( sm == 0.0 ) {
vout[0][0] = v[0][0]; vout[0][1] = v[0][1]; vout[0][2] = v[0][2];
vout[1][0] = v[1][0]; vout[1][1] = v[1][1]; vout[1][2] = v[1][2];
vout[2][0] = v[2][0]; vout[2][1] = v[2][1]; vout[2][2] = v[2][2];
dout[0] = d[0]; dout[1] = d[1]; dout[2] = d[2];
return;
}
if( i < 3 ) {
tresh=(SWIFT_Real)0.2*sm/(n*n);
} else {
tresh=0.0;
}
for(ip=0; ip<n; ip++) {
for(iq=ip+1; iq<n; iq++) {
g = (SWIFT_Real)100.0*fabs(a[ip][iq]);
if( i>3 && fabs(d[ip])+g==fabs(d[ip]) &&
fabs(d[iq])+g==fabs(d[iq])
) {
a[ip][iq]=0.0;
} else if( fabs(a[ip][iq])>tresh ) {
h = d[iq]-d[ip];
if( fabs(h)+g == fabs(h) ) {
t=(a[ip][iq])/h;
} else {
theta=(SWIFT_Real)0.5*h/(a[ip][iq]);
t=(SWIFT_Real)(1.0/(fabs(theta)+sqrt(1.0+theta*theta)));
if (theta < 0.0) t = -t;
}
c=(SWIFT_Real)1.0/sqrt(1+t*t);
s=t*c;
tau=s/((SWIFT_Real)1.0+c);
h=t*a[ip][iq];
z[ip] -= h;
z[iq] += h;
d[ip] -= h;
d[iq] += h;
a[ip][iq]=0.0;
for( j = 0; j < ip; j++ ) {
Rotate( a, j, ip, j, iq, tau, s, g, h );
}
for( j = ip+1; j < iq; j++ ) {
Rotate( a, ip, j, j, iq, tau, s, g, h );
}
for( j = iq+1; j < n; j++ ) {
Rotate( a, ip, j, iq, j, tau, s, g, h );
}
for( j = 0; j < n; j++ ) {
Rotate( v, j, ip, j, iq, tau, s, g, h );
}
nrot++;
}
}
}
for( ip = 0 ; ip < n; ip++ ) {
b[ip] += z[ip];
d[ip] = b[ip];
z[ip] = 0.0;
}
}
cerr << "eigen: too many iterations in Jacobi transform." << endl;
}
示例14: DrawSphere
VOID DrawSphere( HDC hDC, INT Xc, INT Yc )
{
INT i, j, x, y;
DOUBLE theta, phi, phase = clock() / 100;
static VEC G[N][M];
for (i = 0; i < N; i++)
{
theta = i * PI / (N - 1);
for (j = 0; j < M; j++)
{
phi = j * 2 * PI / (M - 1) + phase;
G[i][j].X = R * sin(theta) * cos(phi);
G[i][j].Y = R * sin(theta) * sin(phi);
G[i][j].Z = R * cos(theta);
G[i][j] = Rotate(G[i][j], VecSet(1, 1, 1), 45);
}
}
for (i = 0; i < N; i++)
for (j = 0; j < M; j++)
{
Ps[i][j].x = Xc + G[i][j].X;
Ps[i][j].y = Yc - G[i][j].Z;
}
SelectObject(hDC, GetStockObject(DC_PEN));
SelectObject(hDC, GetStockObject(DC_BRUSH));
SetDCPenColor(hDC, RGB(255, 0, 255));
SetDCBrushColor(hDC, RGB(255, 255, 255));
for (i = 0; i < N - 1; i++)
for (j = 0; j < M - 1; j++)
{
INT img_x, img_y;
COLORREF c, r, g, b;
img_x = j * (Globe.W - 1) / (M - 1);
img_y = i * (Globe.H - 1) / (N - 1);
c = Globe.Bits[img_x + img_y * Globe.W];
r = GetRValue(c);
g = GetGValue(c);
b = GetBValue(c);
c = RGB(b, g, r);
SetDCPenColor(hDC, c);
SetDCBrushColor(hDC, c);
p0 = Ps[i][j];
p1 = Ps[i][j + 1];
p2 = Ps[i + 1][j + 1];
p3 = Ps[i + 1][j];
DrawQuad(hDC, p0, p1, p2, p3, c);
}
/*
for (i = 0; i < N; i++)
{
x = Xc + G[i][0].X;
y = Yc - G[i][0].Z;
MoveToEx(hDC, x , y, NULL);
for (j = 1; j < M; j++)
{
x = Xc + G[i][j].X;
y = Yc - G[i][j].Z;
LineTo(hDC, x, y);
}
}
for (j = 0; j < M; j++)
{
x = Xc + G[0][j].X;
y = Yc - G[0][j].Z;
MoveToEx(hDC, x , y, NULL);
for (i = 1; i < N; i++)
{
x = Xc + G[i][j].X;
y = Yc - G[i][j].Z;
LineTo(hDC, x, y);
}
} */
}
示例15: Graphics
void CRenderTools::RenderQuads(CQuad *pQuads, int NumQuads, int RenderFlags, ENVELOPE_EVAL pfnEval, void *pUser)
{
Graphics()->QuadsBegin();
float Conv = 1/255.0f;
for(int i = 0; i < NumQuads; i++)
{
CQuad *q = &pQuads[i];
float r=1, g=1, b=1, a=1;
if(q->m_ColorEnv >= 0)
{
float aChannels[4];
pfnEval(q->m_ColorEnvOffset/1000.0f, q->m_ColorEnv, aChannels, pUser);
r = aChannels[0];
g = aChannels[1];
b = aChannels[2];
a = aChannels[3];
}
bool Opaque = false;
/* TODO: Analyze quadtexture
if(a < 0.01f || (q->m_aColors[0].a < 0.01f && q->m_aColors[1].a < 0.01f && q->m_aColors[2].a < 0.01f && q->m_aColors[3].a < 0.01f))
Opaque = true;
*/
if(Opaque && !(RenderFlags&LAYERRENDERFLAG_OPAQUE))
continue;
if(!Opaque && !(RenderFlags&LAYERRENDERFLAG_TRANSPARENT))
continue;
Graphics()->QuadsSetSubsetFree(
fx2f(q->m_aTexcoords[0].x), fx2f(q->m_aTexcoords[0].y),
fx2f(q->m_aTexcoords[1].x), fx2f(q->m_aTexcoords[1].y),
fx2f(q->m_aTexcoords[2].x), fx2f(q->m_aTexcoords[2].y),
fx2f(q->m_aTexcoords[3].x), fx2f(q->m_aTexcoords[3].y)
);
float OffsetX = 0;
float OffsetY = 0;
float Rot = 0;
// TODO: fix this
if(q->m_PosEnv >= 0)
{
float aChannels[4];
pfnEval(q->m_PosEnvOffset/1000.0f, q->m_PosEnv, aChannels, pUser);
OffsetX = aChannels[0];
OffsetY = aChannels[1];
Rot = aChannels[2]/360.0f*pi*2;
}
IGraphics::CColorVertex Array[4] = {
IGraphics::CColorVertex(0, q->m_aColors[0].r*Conv*r, q->m_aColors[0].g*Conv*g, q->m_aColors[0].b*Conv*b, q->m_aColors[0].a*Conv*a),
IGraphics::CColorVertex(1, q->m_aColors[1].r*Conv*r, q->m_aColors[1].g*Conv*g, q->m_aColors[1].b*Conv*b, q->m_aColors[1].a*Conv*a),
IGraphics::CColorVertex(2, q->m_aColors[2].r*Conv*r, q->m_aColors[2].g*Conv*g, q->m_aColors[2].b*Conv*b, q->m_aColors[2].a*Conv*a),
IGraphics::CColorVertex(3, q->m_aColors[3].r*Conv*r, q->m_aColors[3].g*Conv*g, q->m_aColors[3].b*Conv*b, q->m_aColors[3].a*Conv*a)};
Graphics()->SetColorVertex(Array, 4);
CPoint *pPoints = q->m_aPoints;
if(Rot != 0)
{
static CPoint aRotated[4];
aRotated[0] = q->m_aPoints[0];
aRotated[1] = q->m_aPoints[1];
aRotated[2] = q->m_aPoints[2];
aRotated[3] = q->m_aPoints[3];
pPoints = aRotated;
Rotate(&q->m_aPoints[4], &aRotated[0], Rot);
Rotate(&q->m_aPoints[4], &aRotated[1], Rot);
Rotate(&q->m_aPoints[4], &aRotated[2], Rot);
Rotate(&q->m_aPoints[4], &aRotated[3], Rot);
}
IGraphics::CFreeformItem Freeform(
fx2f(pPoints[0].x)+OffsetX, fx2f(pPoints[0].y)+OffsetY,
fx2f(pPoints[1].x)+OffsetX, fx2f(pPoints[1].y)+OffsetY,
fx2f(pPoints[2].x)+OffsetX, fx2f(pPoints[2].y)+OffsetY,
fx2f(pPoints[3].x)+OffsetX, fx2f(pPoints[3].y)+OffsetY);
Graphics()->QuadsDrawFreeform(&Freeform, 1);
}
Graphics()->QuadsEnd();
}