int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { XEngine *engine = XEngine::GetInstance(); if( engine->Init(hInstance) == FALSE ) { return -1; } Rect rec(Position(-10000.0, 10000.0), Position(10000.0, -10000.0)); TestScene *scene = new TestScene; scene->SetTime(0); //Scene *scene = new Scene; scene->Init(rec); scene->camera->MoveForwardBy(-40); scene->camera->MoveUpBy(18); scene->camera->Pitch(-XM_PI / 10); Material material; material.ambient = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f); material.diffuse = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f); material.specular = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f); material.power = 9.0f; //material.texture = SRVBatch::GetInstance()->LoadSRV("media/", "cup.jpg"); Particle *fire = new Particle; fire->Init("media/","fire.png"); fire->SetPosition(0, 0, 10); //scene->AddRenderableThing(*fire); SkyBox *sky = new SkyBox; //sky->Init("textures/", "skymap.dds"); sky->Init("textures/", "Above_The_Sea.dds"); //sky->Init("textures/", "desert_skymap.dds"); scene->AddSky(sky); Terrain *terrain = new Terrain; //terrain->Init("terrain/testHight.bmp", "terrain/", "dirt01.dds"); terrain->Init("terrain/heightmap01.bmp", "terrain/", "grass.jpg"); scene->AddTerrain(terrain); Wall *wall = new Wall; wall->Init(30, 30, 0.3); wall->Pitch(XM_PI / 2); wall->SetPosition(0, -3, 0); //scene->AddRenderableThing(*wall); //¿É¼ûÐÔ²âÊÔ Wall *wall0 = new Wall; wall0->Init(30, 30, 0.3); wall0->Pitch(XM_PI / 2); wall0->SetPosition(1000, -3, 0); //scene->AddRenderableThing(*wall0); Obj *obj = new Obj; obj->CreateBox(1, 3, 2, material); obj->SetPosition(5, 1, 12); obj->Yaw(XM_PI / 3); obj->Roll(XM_PI / 3); obj->SetScale(1.3); //scene->AddRenderableThing(*obj); Cube *cube = new Cube; cube->Init(2); cube->Pitch(XM_PI / 3); cube->Roll(XM_PI / 3); cube->SetMaterial(material); //scene->AddRenderableThing(*cube); Ball *ball = new Ball; ball->Init(1); ball->SetPosition(0, 0, 6); Obj *objInWall = new Obj; objInWall->CreateBox(1, 1, 1, material); objInWall->SetPosition(0, 1, 0); ball->AddChild(objInWall); //scene->AddRenderableThing(*ball); Ship *ship = new Ship; //ship->Init(); //ship->SetPosition(-10, 0, 0); //scene->AddRenderableThing(*ship); Model *test = new Model; test->LoadModel("media/", "chair.obj"); test->SetScale(1.7); test->SetPosition(-15, 0, 0); test->Pitch(-1.2); test->Yaw(-1.5); //scene->AddRenderableThing(*test); //SmileBoy *smileBoy= new SmileBoy; //smileBoy->Init(); //smileBoy->SetHandleInput(FALSE); //scene->AddRenderableThing(*smileBoy); Female *female = new Female; female->Init(); //female->SetPosition(-7, 0,0); female->SetHandleInput(TRUE); scene->AddRenderableThing(*female); RenderSystem::GetInstance()->SetShadowOpen(true); engine->LoadScene(scene); { Light *light = new Light; light->type = 0; light->position = XMFLOAT4(0.0f, 5.0f, -5.0f, 1.0f); XMStoreFloat4(&light->direction, XMVector4Normalize(XMVectorSet(1.0f, -1.0f, 0.0f, 0.0f))); light->ambient = XMFLOAT4(0.4f, 0.2f, 0.3f, 1.0f); light->diffuse = XMFLOAT4(0.3f, 0.4f, 0.5f, 1.0f); light->specular = XMFLOAT4(0.5f, 0.3f, 0.2f, 1.0f); light->attenuation0 = 0.0f; light->attenuation1 = 0.0f; light->attenuation2 = 0.0f; light->alpha = 0.0f; light->beta = 0.0f; light->falloff = 0.0f; scene->AddLight(light); } //******************************************* engine->Run(); return 0; }
void CFVec4::Normalise( void ) { XMVECTOR& v4V = *reinterpret_cast<XMVECTOR*>( this ); v4V = XMVector4Normalize( v4V ); }
void CMeshNodePanel::updateSelectedObjectTransform(f32 delta) { EditorScene* scene = EditorScene::getInstance(); if (!scene) return; SNodeInfo* info = scene->GetSelectedNodeInfo(); if (!info) return; const f32 MOVE_UNIT = 10.0f; const f32 SCALING_UNIT = 5.0f; ICameraNode* camera = scene->GetCamera(); XMFLOAT3 look = camera->getLookVector(); XMFLOAT3 up(0, 1.0f, 0); XMFLOAT3 right = camera->getRightVector(); XMVECTOR look_v = XMVectorSet(look.x, 0, look.z, 0); look_v = XMVector4Normalize(look_v); XMStoreFloat3(&look, look_v); XMFLOAT3 movement(0, 0, 0); XMFLOAT3 scaling(0, 0, 0); if (GetAsyncKeyState('W') & 0x8000) { movement = math::VectorMultiply(look, delta * MOVE_UNIT); } if (GetAsyncKeyState('S') & 0x8000) { movement = math::VectorMultiply(look, -delta * MOVE_UNIT); } if (GetAsyncKeyState('A') & 0x8000) { movement = math::VectorMultiply(right, -delta * MOVE_UNIT); } if (GetAsyncKeyState('D') & 0x8000) { movement = math::VectorMultiply(right, delta * MOVE_UNIT); } if (GetAsyncKeyState('R') & 0x8000) { movement = math::VectorMultiply(up, delta * MOVE_UNIT); } if (GetAsyncKeyState('F') & 0x8000) { movement = math::VectorMultiply(up, -delta * MOVE_UNIT); } if (GetAsyncKeyState(VK_ADD) & 0x8000) { scaling = XMFLOAT3(1.0f, 1.0f, 1.0f); } if (GetAsyncKeyState(VK_SUBTRACT) & 0x8000) { scaling = XMFLOAT3(-1.0f, -1.0f, -1.0f); } scaling = math::VectorMultiply(scaling, delta * SCALING_UNIT); info->Position = math::VectorAdd(info->Position, movement); info->Scaling = math::VectorAdd(info->Scaling, scaling); scene->UpdateNodeInfo(info); ShowNodeInfo(info); }
Vector& Vector::normalize() { m_vector = XMVector4Normalize(m_vector); return *this; }
void CLightPanel::updateSelectedLightInfo(f32 delta) { EditorScene* scene = EditorScene::getInstance(); if (!scene) return; SLightNodeInfo* info = scene->GetSelectedLightNodeInfo(); if (!info) return; const f32 MOVE_UNIT = 10.0f; const f32 SCALING_UNIT = 5.0f; ICameraNode* camera = scene->GetCamera(); XMFLOAT3 look = camera->getLookVector(); XMFLOAT3 up(0, 1.0f, 0); XMFLOAT3 right = camera->getRightVector(); XMVECTOR look_v = XMVectorSet(look.x, 0, look.z, 0); look_v = XMVector4Normalize(look_v); XMStoreFloat3(&look, look_v); XMFLOAT3 movement(0, 0, 0); f32 scaling = 0; if (GetAsyncKeyState('W') & 0x8000) { movement = math::VectorMultiply(look, delta * MOVE_UNIT); } if (GetAsyncKeyState('S') & 0x8000) { movement = math::VectorMultiply(look, -delta * MOVE_UNIT); } if (GetAsyncKeyState('A') & 0x8000) { movement = math::VectorMultiply(right, -delta * MOVE_UNIT); } if (GetAsyncKeyState('D') & 0x8000) { movement = math::VectorMultiply(right, delta * MOVE_UNIT); } if (GetAsyncKeyState('R') & 0x8000) { movement = math::VectorMultiply(up, delta * MOVE_UNIT); } if (GetAsyncKeyState('F') & 0x8000) { movement = math::VectorMultiply(up, -delta * MOVE_UNIT); } if (GetAsyncKeyState(VK_ADD) & 0x8000) { scaling = SCALING_UNIT * delta; } if (GetAsyncKeyState(VK_SUBTRACT) & 0x8000) { scaling = -SCALING_UNIT * delta; } info->Position = math::VectorAdd(info->Position, movement); info->Range += scaling; if (info->Range < 0.1f) info->Range = 0.1f; scene->UpdateLightNodeInfo(info); ShowNodeInfo(info->Id); }
void CameraObj::UpdateCBuffer(UINT screenWidth, UINT screenHeight) { TransformData tDataTemp = transform->transformData; //XMVECTOR pos = XMVectorSet(tDataTemp.pos.x, tDataTemp.pos.y, tDataTemp.pos.z, 1.0f); //XMVECTOR rotTemp = XMVectorSet(tDataTemp.rot.x, tDataTemp.rot.y, tDataTemp.rot.z, tDataTemp.rot.w); ////Load the stuff XMFLOAT4 rotQuad = XMFLOAT4(tDataTemp.rot.x, tDataTemp.rot.y, tDataTemp.rot.z, tDataTemp.rot.w); //använd denna sen //XMFLOAT4 rotQuad = XMFLOAT4(0, 0, -1, 0); //hårkodad XMVECTOR rotQuadVec = XMLoadFloat4(&rotQuad); rotQuadVec = XMVector4Normalize(rotQuadVec); XMFLOAT3 pos = XMFLOAT3(tDataTemp.pos.x, tDataTemp.pos.y, tDataTemp.pos.z); //XMFLOAT3 pos = XMFLOAT3(0, 0, 200);//hårkodad XMVECTOR posVec = XMLoadFloat3(&pos); ////Load standard vectors XMFLOAT3 startUp = XMFLOAT3(0, 1, 0); XMVECTOR startUpVec = XMLoadFloat3(&startUp); XMFLOAT3 startTar = XMFLOAT3(0, 0, 1); XMVECTOR startTarVec = XMLoadFloat3(&startTar); XMMATRIX rotMatrix = XMMatrixRotationQuaternion(rotQuadVec); startUpVec = XMVector3Transform(startUpVec, rotMatrix); startTarVec = XMVector3Transform(startTarVec, rotMatrix); XMFLOAT3 derpTar; XMStoreFloat3(&derpTar, startTarVec); XMMATRIX cameraMat = XMMatrixLookToLH(posVec, startTarVec, startUpVec); //XMVECTOR rot = XMVector3Rotate(XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f), rotTemp); //+ positionen eller nått sånt, se denna //XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); //XMMATRIX view = XMMatrixLookAtRH(pos, rot, up); XMMATRIX projection; if (cameraData.isOrtho == 0) { float aspect = (float)screenWidth / (float)screenHeight; projection = XMMatrixPerspectiveFovLH( cameraData.hAngle,//cameraData.hAngle, aspect, //aspect ratio? 1.0f, 4000 ); } else { float fovinv = (float)screenHeight / (float)screenWidth; projection = XMMatrixOrthographicLH(cameraData.hAngle, cameraData.hAngle * fovinv, 1.0f, 4000.0f); } XMMATRIX view = cameraMat; XMStoreFloat4x4(&cameraCBufferData.view, XMMatrixTranspose(view)); XMStoreFloat4x4(&cameraCBufferData.projection, XMMatrixTranspose(projection)); cameraCBufferData.cameraPos[0] = transform->transformData.pos.x; cameraCBufferData.cameraPos[1] = transform->transformData.pos.y; cameraCBufferData.cameraPos[2] = transform->transformData.pos.z; cameraCBufferData.cameraPos[3] = 1; gDeviceContext->UpdateSubresource(cameraCbuffer, 0, NULL, &cameraCBufferData, 0, 0); }