_Use_decl_annotations_ void XM_CALLCONV Camera::SetCameraView(_In_ XMMATRIX mView) { //m_mView = mView; XMMATRIX mInvView = XMMatrixInverse(nullptr, mView); SetWorld(mInvView); }
bool cPlayer::MoveToWorld(const char * a_WorldName) { cWorld * World = cRoot::Get()->GetWorld(a_WorldName); if (World == NULL) { LOG("%s: Couldn't find world \"%s\".", __FUNCTION__, a_WorldName); return false; } eDimension OldDimension = m_World->GetDimension(); // Remove all links to the old world m_World->RemovePlayer(this); m_ClientHandle->RemoveFromAllChunks(); m_World->RemoveEntity(this); // If the dimension is different, we can send the respawn packet // http://wiki.vg/Protocol#0x09 says "don't send if dimension is the same" as of 2013_07_02 m_ClientHandle->MoveToWorld(*World, (OldDimension != World->GetDimension())); // Add player to all the necessary parts of the new world SetWorld(World); World->AddEntity(this); World->AddPlayer(this); return true; }
bool CRenderPipeline::Render(CRenderOperation* op,RenderParam* rp) { Ast( NULL != rp); SetRenderStyle(rp->m_RS); SetWorld( rp->m_Mat ); return RenderEx( op ); }
bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn) { ASSERT(a_World != NULL); if (GetWorld() == a_World) { // Don't move to same world return false; } // Send the respawn packet: if (a_ShouldSendRespawn && (m_ClientHandle != NULL)) { m_ClientHandle->SendRespawn(a_World->GetDimension()); } // Remove player from the old world SetWorldTravellingFrom(GetWorld()); // cChunk handles entity removal GetWorld()->RemovePlayer(this, false); // Queue adding player to the new world, including all the necessary adjustments to the object a_World->AddPlayer(this); SetWorld(a_World); // Chunks may be streamed before cWorld::AddPlayer() sets the world to the new value return true; }
int main(){ // define dois pontos arbitrarios point *p1, *p2; bufferdevice * dispositivo; palette * palheta; window * janela; SetWorld(0, 30, 0, 30); // Define o tamanho do mundo dispositivo = CreateBuffer(640,480); // cria um dispositivo palheta = CreatePalette(6); SetColor(0,0,0,palheta); SetColor(1,0,0,palheta); SetColor(0,1,0,palheta); SetColor(0,0,1,palheta); SetColor(1,1,1,palheta); p1 = SetPoint(5, 5, 1); p2 = SetPoint(10,4, 1); janela = CreateWindow(0, 10, 0, 10); DrawLine(p1, p2, janela, dispositivo, 1); DumpX(dispositivo, palheta); return 0; }
Geometry::Geometry(ID3D10Device* device, Resources::ModelObj* model, const D3DXMATRIX& world) : mDevice(device) , mModel(model) , mDrawableAABB(mDevice, mAABB) { SetWorld(world); }
int main(int argc, char ** argv) { palette * palheta; bufferdevice * dispositivo; window * janela; object * poligono1, * poligono2, * poligono3; SetWorld(-20, 10, -20, 15); // Define o tamanho do mundo dispositivo = CreateBuffer(640,480); // cria um dispositivo palheta = CreatePalette(4); SetColor(0,0,0,palheta); SetColor(1,0,0,palheta); SetColor(0,0,1,palheta); SetColor(1,1,0,palheta); poligono1 = CreateObject(5); poligono2 = CreateObject(4); SetObject(SetPoint(-9.0,-8.0,1), poligono1); SetObject(SetPoint(-7.0,-3.0,1), poligono1); SetObject(SetPoint(-4.0,-4.0,1), poligono1); SetObject(SetPoint(-3.0,-6.0,1), poligono1); SetObject(SetPoint(-6.0,-9.0,1), poligono1); SetObject(SetPoint(-6.0,-2.0,2), poligono2); SetObject(SetPoint(-1.0,-2.0,2), poligono2); SetObject(SetPoint(-1.0,-6.0,2), poligono2); SetObject(SetPoint(-6.0,-6.0,2), poligono2); poligono1 = Translate(poligono1,5,5); // centraliza em relação a origem do sistema poligono2 = Translate(poligono2,5,5); poligono3 = Translate(poligono2,-1.5,-1.0); poligono3 = Rotate(poligono3,45); poligono3 = Translate(poligono3,1.5,1.0); poligono3 = ChangeColor(poligono3,3); poligono1 = Scale(poligono1,0.4,0.4); poligono2 = Scale(poligono2,0.4,0.4); poligono3 = Scale(poligono3,0.4,0.4); janela = CreateWindow(-2.0,2.0,-2.0,2.0); // define uma janela de visualização DrawObject(poligono1,janela,dispositivo); // desenha o poligono 1 dentro da janela no buffer do dispositivo DrawObject(poligono2,janela,dispositivo); // desenha o poligono 2 dentro da janela no buffer do dispositivo DrawObject(poligono3,janela,dispositivo); // desenha o poligono 3 dentro da janela no buffer do dispositivo /* * O sistema RGB é aditivo pois cada cor nesse modelo é representada por uma soma ponderada de três componentes * primárias (o vermelho, o verde e o azul). */ DumpX(dispositivo,palheta); // desenha o buffer na tela //DumpOpenGL(argc,argv,dispositivo,palheta); return 0; }
//! Constructor. Object3D::Object3D(ObjectType type, XMFLOAT3 position, XMFLOAT3 rotation, XMFLOAT3 scale) { SetPosition(position); SetRotation(rotation); SetScale(scale); SetBoundingBoxVisible(false); SetName("Object"); SetDefualtScale(1.0f); SetMaterials(GLib::Colors::White); SetId(-1); SetType(type); SetWorld(nullptr); mAlive = true; }
void CBox::ResetPosition(b2World & world) { //destroy stuff (memory management, otherwise they build up) m_body->DestroyFixture(m_body->GetFixtureList()); world.DestroyBody(m_body); n++; //m_shape.SetOrigin(5,5); m_bodyDef.position.Set(300.0f/PPM,-300.0f/PPM-n*5/PPM); m_bodyDef.angularVelocity = 0; //m_bodyDef.angle = 270; m_bodyDef.linearVelocity.Set(0, 60); //reset fixture and body SetWorld(world); //reset shape update(); }
bool Link::SetItemInfo ( char *szName, int iData ) { if (stricmp(szName,"World")==0) { SetWorld((CWorld*)iData); return true; } else if (stricmp(szName,"FromSide")==0) { from_side = iData; return true; } else if (stricmp(szName,"ToSide")==0) { to_side = iData; return true; } return false; }
//-------------------------------------------------------------------------------------- // Client can call this to change the position and direction of camera //-------------------------------------------------------------------------------------- _Use_decl_annotations_ void XM_CALLCONV Camera::SetViewParams(FXMVECTOR vEyePt, FXMVECTOR vLookatPt, FXMVECTOR vWorldUp) { // Calc the view matrix XMMATRIX view = XMMatrixLookAtLH(vEyePt, vLookatPt, vWorldUp); //m_mView = view; XMMATRIX mInvView = XMMatrixInverse(nullptr, view); SetWorld(mInvView); //// The axis basis vectors and camera position are stored inside the //// position matrix in the 4 rows of the camera's world matrix. //// To figure out the yaw/pitch of the camera, we just need the Z basis vector //XMFLOAT3 zBasis; //XMStoreFloat3(&zBasis, mInvView.r[2]); //m_fCameraYawAngle = atan2f(zBasis.x, zBasis.z); //float fLen = sqrtf(zBasis.z * zBasis.z + zBasis.x * zBasis.x); //m_fCameraPitchAngle = -atan2f(zBasis.y, fLen); }
bool CEditRenderPipeline::Render( CRenderOperation* op,RenderParam* rp ) { Ast( NULL != rp); SetRenderStyle(rp->m_RS); SetWorld( rp->m_Mat ); if(IsPixelFillCount) { StencilParam tmpStencilParam; tmpStencilParam.m_bEnable=TRUE; tmpStencilParam.m_nCompFun=CMP_ALWAYS; tmpStencilParam.m_nRefrence=0; tmpStencilParam.m_nFailedFlag=STENCILOP_KEEP; tmpStencilParam.m_nZFailedFlag=STENCILOP_KEEP; tmpStencilParam.m_nPassFlag=STENCILOP_INCRSAT; tmpStencilParam.m_nReadMask=0xFFFFFFFF; tmpStencilParam.m_nWriteMask=0xFFFFFFFF; //开启模板测试 _SetRenderStyle( RS_STENCILENABLE, DWORD(tmpStencilParam.m_bEnable) ); _SetRenderStyle( RS_STENCILREF, DWORD(tmpStencilParam.m_nRefrence) ); _SetRenderStyle( RS_STENCILFUNC, tmpStencilParam.m_nCompFun ); _SetRenderStyle( RS_STENCILFAIL, tmpStencilParam.m_nFailedFlag ); _SetRenderStyle( RS_STENCILZFAIL, tmpStencilParam.m_nZFailedFlag ); _SetRenderStyle( RS_STENCILPASS, tmpStencilParam.m_nPassFlag ); _SetRenderStyle( RS_STENCILMASK, tmpStencilParam.m_nReadMask ); _SetRenderStyle( RS_STENCILWRITEMASK, tmpStencilParam.m_nWriteMask ); //绑定像素填充率计算的shader } else { //将模版缓存恢复到原来状态!即RS中 但是引擎没有封装,而且也不适合每一桢都调用 //所有将模版恢复到原来状态的设置代码写在外面 } return RenderEx( op ); }
inline void StateStackClass::pvtDrawObject(UInt32 operation, ObjectInstance *objInst, const Pmatrix *rot, const Ppoint *pos, const float sx, const float sy, const float sz, const float scale) { UInt32 clipFlag; float MaxLODRange; static int in = 0; ShiAssert(objInst); PushAll(); // Set up our transformations CompoundTransform(rot,pos); SetWorld(rot,pos); if(operation & OP_WARP) { Pmatrix tempM; ShiAssert((sx > 0.0f) && (sx <= 1.0f)); ShiAssert((sy > 0.0f) && (sy <= 1.0f)); ShiAssert((sz > 0.0f) && (sz <= 1.0f)); Pmatrix stretchM = { sx, 0.f, 0.f, 0.f, sy, 0.f, 0.f, 0.f, sz }; tempM = Rotation; MatrixMult(&tempM,&stretchM,&Rotation); D3DFrame::Matrix mS,mT; mT = mW; mS.InitIdentity(); mS.m[0][0]=sx; mS.m[1][1]=sy; mS.m[2][2]=sz; mW = mS*mT; } if(scale != 1.f) { Pmatrix tempM; Pmatrix scaleM = { scale, 0.f, 0.f, 0.f, scale, 0.f, 0.f, 0.f, scale }; tempM = Rotation; MatrixMult(&tempM,&scaleM,&Rotation); D3DFrame::Matrix mS,mT; mT = mW; mS.InitIdentity(); mS.m[0][0]=scale; mS.m[1][1]=scale; mS.m[2][2]=scale; mW = mS*mT; } // Store the adjusted range for LOD determinations LODRange = Xlation.x * LODBiasInv; // Choose the appropriate LOD of the object to be drawn CurrentInstance = objInst; if (objInst->ParentObject) { if (g_bSlowButSafe && F4IsBadCodePtr((FARPROC) objInst->ParentObject)) // JB 010220 CTD (too much CPU) CurrentLOD = 0; // JB 010220 CTD else // JB 010220 CTD if (objInst->id < 0 || objInst->id >= TheObjectListLength || objInst->TextureSet < 0) // JB 010705 CTD second try { ShiAssert(FALSE); CurrentLOD = 0; } else CurrentLOD = objInst->ParentObject->ChooseLOD(LODRange,&LODused,&MaxLODRange); if(CurrentLOD) { // Decide if we need clipping, or if the object is totally off screen clipFlag = CheckBoundingSphereClipping(); // Continue only if some part of the bounding volume is on screen if (clipFlag != OFF_SCREEN) { // Set the jump pointers to turn on/off clipping if (clipFlag == ON_SCREEN) { Transform = TransformNoClip; DrawPrimJumpTable = DrawPrimNoClipJumpTable; } else { Transform = TransformWithClip; DrawPrimJumpTable = DrawPrimWithClipJumpTable; } // Choose perspective correction or not // if ((Xlation.x > CurrentInstance->Radius() * PERSP_CORR_RADIUS_MULTIPLIER) && // !(CurrentLOD->flags & ObjectLOD::PERSP_CORR)) // { // RenderStateTable = RenderStateTableNPC; // } // else // { RenderStateTable = RenderStateTablePC; // } in ++; if (in == 1) { verts = 0; } // Draw the object CurrentLOD->Draw(); // if (in == 1) // { // if (verts) // { // MonoPrint ("Obj %d:%d %d : %d\n", objInst->id, LODused, (int) MaxLODRange, verts); // } // } in --; } } } PopAll(); }
bool UDemoNetDriver::InitConnect( FNetworkNotify* InNotify, const FURL& ConnectURL, FString& Error ) { if ( GetWorld() == nullptr ) { UE_LOG( LogDemo, Error, TEXT( "GetWorld() == nullptr" ) ); return false; } if ( GetWorld()->GetGameInstance() == nullptr ) { UE_LOG( LogDemo, Error, TEXT( "GetWorld()->GetGameInstance() == nullptr" ) ); return false; } UGameInstance* GameInstance = GetWorld()->GetGameInstance(); // handle default initialization if ( !InitBase( true, InNotify, ConnectURL, false, Error ) ) { GameInstance->HandleDemoPlaybackFailure( EDemoPlayFailure::Generic, FString( TEXT( "InitBase FAILED" ) ) ); return false; } ResetDemoState(); // open the pre-recorded demo file FileAr = IFileManager::Get().CreateFileReader( *DemoFilename ); if ( !FileAr ) { Error = FString::Printf( TEXT( "Couldn't open demo file %s for reading" ), *DemoFilename ); UE_LOG( LogDemo, Error, TEXT( "UDemoNetDriver::InitConnect: %s" ), *Error ); GameInstance->HandleDemoPlaybackFailure( EDemoPlayFailure::DemoNotFound, FString( EDemoPlayFailure::ToString( EDemoPlayFailure::DemoNotFound ) ) ); return false; } // Playback, local machine is a client, and the demo stream acts "as if" it's the server. ServerConnection = ConstructObject<UNetConnection>( UDemoNetConnection::StaticClass() ); ServerConnection->InitConnection( this, USOCK_Pending, ConnectURL, 1000000 ); // use the same byte format regardless of platform so that the demos are cross platform // DEMO_FIXME: This is messing up for some reason, investigate //FileAr->SetByteSwapping( true ); FNetworkDemoHeader DemoHeader; (*FileAr) << DemoHeader; // Check magic value if ( DemoHeader.Magic != NETWORK_DEMO_MAGIC ) { Error = FString( TEXT( "Demo file is corrupt" ) ); UE_LOG( LogDemo, Error, TEXT( "UDemoNetDriver::InitConnect: %s" ), *Error ); GameInstance->HandleDemoPlaybackFailure( EDemoPlayFailure::Corrupt, Error ); return false; } // Check version if ( DemoHeader.Version != NETWORK_DEMO_VERSION ) { Error = FString( TEXT( "Demo file version is incorrect" ) ); UE_LOG( LogDemo, Error, TEXT( "UDemoNetDriver::InitConnect: %s" ), *Error ); GameInstance->HandleDemoPlaybackFailure( EDemoPlayFailure::InvalidVersion, Error ); return false; } // Create fake control channel ServerConnection->CreateChannel( CHTYPE_Control, 1 ); DemoTotalFrames = DemoHeader.NumFrames; DemoTotalTime = DemoHeader.TotalTime; UE_LOG( LogDemo, Log, TEXT( "Starting demo playback with demo. Filename: %s, Frames: %i, Version %i" ), *DemoFilename, DemoTotalFrames, DemoHeader.Version ); // Bypass UDemoPendingNetLevel FString LoadMapError; FURL DemoURL; DemoURL.Map = DemoHeader.LevelName; FWorldContext * WorldContext = GEngine->GetWorldContextFromWorld( GetWorld() ); if ( WorldContext == NULL ) { Error = FString::Printf( TEXT( "No world context" ), *DemoFilename ); UE_LOG( LogDemo, Error, TEXT( "UDemoNetDriver::InitConnect: %s" ), *Error ); GameInstance->HandleDemoPlaybackFailure( EDemoPlayFailure::Generic, FString( TEXT( "No world context" ) ) ); return false; } GetWorld()->DemoNetDriver = NULL; SetWorld( NULL ); auto NewPendingNetGame = NewObject<UDemoPendingNetGame>(); NewPendingNetGame->DemoNetDriver = this; WorldContext->PendingNetGame = NewPendingNetGame; if ( !GEngine->LoadMap( *WorldContext, DemoURL, NewPendingNetGame, LoadMapError ) ) { Error = LoadMapError; UE_LOG( LogDemo, Error, TEXT( "UDemoNetDriver::InitConnect: LoadMap failed: failed: %s" ), *Error ); GameInstance->HandleDemoPlaybackFailure( EDemoPlayFailure::Generic, FString( TEXT( "LoadMap failed" ) ) ); return false; } SetWorld( WorldContext->World() ); WorldContext->World()->DemoNetDriver = this; WorldContext->PendingNetGame = NULL; // Remember where we are const int32 OldPos = FileAr->Tell(); // Jump to meta data FileAr->Seek( DemoHeader.MetaDataOffset ); // Read meta data for ( int32 i = 0; i < DemoHeader.NumStreamingLevels; ++i ) { ULevelStreamingKismet* StreamingLevel = static_cast<ULevelStreamingKismet*>(StaticConstructObject(ULevelStreamingKismet::StaticClass(), GetWorld(), NAME_None, RF_NoFlags, NULL ) ); StreamingLevel->bShouldBeLoaded = true; StreamingLevel->bShouldBeVisible = true; StreamingLevel->bShouldBlockOnLoad = false; StreamingLevel->bInitiallyLoaded = true; StreamingLevel->bInitiallyVisible = true; FString PackageName; FString PackageNameToLoad; (*FileAr) << PackageName; (*FileAr) << PackageNameToLoad; (*FileAr) << StreamingLevel->LevelTransform; StreamingLevel->PackageNameToLoad = FName( *PackageNameToLoad ); StreamingLevel->SetWorldAssetByPackageName( FName( *PackageName ) ); GetWorld()->StreamingLevels.Add( StreamingLevel ); UE_LOG( LogDemo, Log, TEXT( " Loading streamingLevel: %s, %s" ), *PackageName, *PackageNameToLoad ); } // Jump back to start of stream FileAr->Seek( OldPos ); // Remember where the meta data is, this is where we must stop reading the demo stream EndOfStreamOffset = DemoHeader.MetaDataOffset; return true; }
bool UDemoNetDriver::InitConnect( FNetworkNotify* InNotify, const FURL& ConnectURL, FString& Error ) { // handle default initialization if ( !InitBase( true, InNotify, ConnectURL, false, Error ) ) { return false; } // open the pre-recorded demo file FileAr = IFileManager::Get().CreateFileReader( *DemoFilename ); if ( !FileAr ) { Error = FString::Printf( TEXT( "Couldn't open demo file %s for reading" ), *DemoFilename ); UE_LOG( LogDemo, Error, TEXT( "UDemoNetDriver::InitConnect: %s" ), *Error ); return false; } // Playback, local machine is a client, and the demo stream acts "as if" it's the server. ServerConnection = ConstructObject<UNetConnection>( UDemoNetConnection::StaticClass() ); ServerConnection->InitConnection( this, USOCK_Pending, ConnectURL, 1000000 ); #if 1 // Create fake control channel ServerConnection->CreateChannel( CHTYPE_Control, 1 ); #endif // use the same byte format regardless of platform so that the demos are cross platform // DEMO_FIXME: This is messing up for some reason, investigate //FileAr->SetByteSwapping( true ); int32 EngineVersion = 0; (*FileAr) << EngineVersion; (*FileAr) << PlaybackTotalFrames; UE_LOG( LogDemo, Log, TEXT( "Starting demo playback with demo. Filename: %s, Frames: %i, Version %i" ), *DemoFilename, PlaybackTotalFrames, EngineVersion ); #if 1 // Bypass UDemoPendingNetLevel FString LevelName; (*FileAr) << LevelName; FString LoadMapError; FURL DemoURL; DemoURL.Map = LevelName; FWorldContext * WorldContext = GEngine->GetWorldContextFromWorld( World ); if ( WorldContext == NULL ) { Error = FString::Printf( TEXT( "No world context" ), *DemoFilename ); UE_LOG( LogDemo, Error, TEXT( "UDemoNetDriver::InitConnect: %s" ), *Error ); return false; } World->DemoNetDriver = NULL; SetWorld( NULL ); UDemoPendingNetGame * NewPendingNetGame = new UDemoPendingNetGame( FPostConstructInitializeProperties() ); NewPendingNetGame->DemoNetDriver = this; WorldContext->PendingNetGame = NewPendingNetGame; if ( !GEngine->LoadMap( *WorldContext, DemoURL, NewPendingNetGame, LoadMapError ) ) { Error = LoadMapError; UE_LOG( LogDemo, Error, TEXT( "UDemoNetDriver::InitConnect: LoadMap failed: failed: %s" ), *Error ); return false; } SetWorld( WorldContext->World() ); WorldContext->World()->DemoNetDriver = this; WorldContext->PendingNetGame = NULL; #endif int32 NumStreamingLevels = 0; (*FileAr) << NumStreamingLevels; for ( int32 i = 0; i < NumStreamingLevels; ++i ) { ULevelStreamingKismet* StreamingLevel = static_cast<ULevelStreamingKismet*>(StaticConstructObject(ULevelStreamingKismet::StaticClass(), GetWorld(), NAME_None, RF_NoFlags, NULL ) ); StreamingLevel->bShouldBeLoaded = true; StreamingLevel->bShouldBeVisible = true; StreamingLevel->bShouldBlockOnLoad = false; StreamingLevel->bInitiallyLoaded = true; StreamingLevel->bInitiallyVisible = true; FString PackageName; FString PackageNameToLoad; (*FileAr) << PackageName; (*FileAr) << PackageNameToLoad; (*FileAr) << StreamingLevel->LevelTransform; StreamingLevel->PackageNameToLoad = FName( *PackageNameToLoad ); StreamingLevel->SetWorldAssetByPackageName( FName( *PackageName ) ); GetWorld()->StreamingLevels.Add( StreamingLevel ); UE_LOG( LogDemo, Log, TEXT( " Loading streamingLevel: %s, %s" ), *PackageName, *PackageNameToLoad ); } DemoDeltaTime = 0; return true; }