void AasRenderer::RenderGeometryShadow(gfx::AnimatedModel * model, const gfx::AnimatedModelParams & params, const gfx::Light3d & globalLight, float alpha) { // Find or create render caching data for the submesh auto &renderData = mRenderDataCache[model->GetHandle()]; if (!renderData) { renderData = std::make_unique<AasRenderData>(); } mDevice.SetMaterial(mGeometryShadowMaterial); auto d3d = mDevice.GetDevice(); d3d->SetVertexShaderConstantF(0, &mDevice.GetCamera().GetViewProj()._11, 4); d3d->SetVertexShaderConstantF(4, &globalLight.dir.x, 1); XMFLOAT4 floats{ params.offsetZ, 0, 0, 0 }; d3d->SetVertexShaderConstantF(5, &floats.x, 1); floats.x = alpha; d3d->SetVertexShaderConstantF(6, &floats.x, 1); auto materialIds(model->GetSubmeshes()); for (size_t i = 0; i < materialIds.size(); ++i) { auto submesh(model->GetSubmesh(params, i)); auto &submeshData = GetSubmeshData(*renderData, i, *submesh); submeshData.binding.Bind(); d3d->SetIndices(submeshData.idxBuffer->GetBuffer()); D3DLOG(d3d->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, submesh->GetVertexCount(), 0, submesh->GetPrimitiveCount())); } }
void RenderSystem::DrawIndexedPrimitive(sVertexBuffer& vb, int offestVertex, int nVertex, sIndexBuffer& ib, int offsetPolygon, int nPolygon) { SetVertexDeclaration(vb); SetIndices(ib); SetStreamSource(vb); HRESULT hr = lpD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,offestVertex,nVertex,3*offsetPolygon,nPolygon); assert(hr== D3D_OK); }
/// /// \brief MetaDataset::MetaDataset /// \param name Name of this dataset as displayed to user /// \param main_window Main window of the program /// \param log_file The log file /// \param directory The current global working directory /// \param method_description The description of the method used /// \param endmember_selection The string used by the user to select endmembers /// \param method An enum specifying the method /// \param parent_datasets The datasets from which this dataset is extracted /// MetaDataset::MetaDataset(QString name, MainWindow *main_window, QString *directory, QString method_description, MetaMethod::Method method, QList<QSharedPointer<VespucciDataset> > parent_datasets) : VespucciDataset(name, main_window, directory) { parent_datasets_ = parent_datasets; if(!ParentsValid()){ throw std::runtime_error("Improper input to MetaDataset constructor"); cerr << "Improper input to MetaDataset constructor\n"; } method_ = method; method_description_ = method_description; mat spectra; vec wavelength = parent_datasets_[0]->wavelength(); vec x; vec y; switch(method_) { case MetaMethod::AverageSpectra : try{ spectra = ProcessAverage(x, y); } catch(std::exception e){ throw std::runtime_error("MetaDataset::ProcessAverage"); } break; case MetaMethod::ConcatenateDatasets : try{ spectra = Concatenate(x, y); } catch(std::exception e){ throw std::runtime_error("MetaDataset::Concatenate"); } break; default: throw std::runtime_error("Improper input to MetaDataset"); } try{ SetData(spectra, wavelength, x, y); SetParentDatasetIndices(parent_coordinates_); } catch(std::exception e){ throw std::runtime_error("Failure to set data in MetaDataset constructor"); } vec indices_temp(spectra.n_cols); for (uword i = 0; i < indices_temp.n_elem; ++i){ indices_temp(i) = i; } SetIndices(indices_temp); }
void TerrainBorderRenderable::Render(HippoD3d9Device* pdevice, unsigned int escapeTime) { auto device = Globals::GetDevice()->GetDeviceD3D9(); RS_HELP_OBJ(device, D3DRS_ALPHABLENDENABLE, TRUE); RS_HELP_OBJ(device, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); RS_HELP_OBJ(device, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); //RS_HELP_OBJ(device, D3DRS_ZWRITEENABLE, false); RS_HELP_OBJ(device, D3DRS_CULLMODE, D3DCULL_CCW); D3DXMATRIX matrix; D3DXMatrixIdentity(&matrix); HRESULT v = m_fxhandle->SetMatrix("g_mWorld", &matrix); //wvp matrix auto proj = Globals::GetRender()->GetProjMatrix(); auto view = Globals::GetRender()->GetViewMatrix(); D3DXMATRIX vp = (*view)*(*proj); v = m_fxhandle->SetMatrix("g_mViewProjection", &vp); //time float time = GetTickCount()*0.001f; v = m_fxhandle->SetValue("g_fTime", &time, sizeof(float)); //viewmatrix const D3DXVECTOR3* camPos = Globals::GetCurrentCamera()->GetPos(); v = m_fxhandle->SetMatrix("ViewMatrix", view); v = m_fxhandle->SetValue("g_camerapos", camPos, sizeof(D3DXVECTOR3)); //texture v = m_fxhandle->SetTexture("g_MeshTexture", m_pTextrue.get()); //threshold D3DXVECTOR4 threshold = D3DXVECTOR4(800.f, 0.99f, 0, 0); v = m_fxhandle->SetValue("threshold", &threshold, sizeof(D3DXVECTOR4)); device->SetStreamSource(0, m_pVB.get(), 0, sizeof(TerrainVertex)); device->SetVertexDeclaration(m_pVertexDecl.get()); device->SetIndices(m_pIB.get()); UINT iPass, totalPasses; m_fxhandle->Begin(&totalPasses, 0); m_fxhandle->BeginPass(0); device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, // 将要绘制的索引缓冲区的起始地址 0, // 索引数组中最小的索引值 16, // 要绘制的索引数组中的顶点数量 0, // 从索引数组中的第几个元素开始绘制图元 8); // 绘制的图元数量 m_fxhandle->EndPass(); m_fxhandle->End(); }
void VertexArray::Init(const TriangleMesh *mesh) { const int ctVertices = mesh->mPositions.size(); const int ctIndices = mesh->mIndices.size(); AddAttributes(mesh->GetVertexAttribDefs()); Init(ctVertices, ctVertices); SetVertices(static_cast<const GLvoid*>(mesh->GetVertexArray().data()), 0, ctVertices); if(ctIndices > 0) { void *indices = mesh->GetIndices(); SetIndices(indices, ctIndices, mesh->GetIndexType()); delete[] indices; } }
void DatabaseCorrelation::SetFromNode(DataNode *parentNode) { if(parentNode == 0) return; DataNode *searchNode = parentNode->GetNode("DatabaseCorrelation"); if(searchNode == 0) return; DataNode *node; if((node = searchNode->GetNode("name")) != 0) SetName(node->AsString()); if((node = searchNode->GetNode("numStates")) != 0) SetNumStates(node->AsInt()); if((node = searchNode->GetNode("method")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 5) SetMethod(CorrelationMethod(ival)); } else if(node->GetNodeType() == STRING_NODE) { CorrelationMethod value; if(CorrelationMethod_FromString(node->AsString(), value)) SetMethod(value); } } if((node = searchNode->GetNode("databaseNames")) != 0) SetDatabaseNames(node->AsStringVector()); if((node = searchNode->GetNode("databaseNStates")) != 0) SetDatabaseNStates(node->AsIntVector()); if((node = searchNode->GetNode("databaseTimes")) != 0) SetDatabaseTimes(node->AsDoubleVector()); if((node = searchNode->GetNode("databaseCycles")) != 0) SetDatabaseCycles(node->AsIntVector()); if((node = searchNode->GetNode("indices")) != 0) SetIndices(node->AsIntVector()); if((node = searchNode->GetNode("condensedTimes")) != 0) SetCondensedTimes(node->AsDoubleVector()); if((node = searchNode->GetNode("condensedCycles")) != 0) SetCondensedCycles(node->AsIntVector()); }
FaceMesh::FaceMesh() { mVertices = new Vertices(); mIndices = new Indices(); mVertices->Allocate(sizeof(Vertex), 4); mIndices->Allocate(4); mVertices->PutValues(gVertices); mIndices->PutValues(gIndices); SetVertices(mVertices); SetIndices(mIndices); mIndices->mTriangleMode = TrianglesModeTrianglesStrip; }
void AasRenderer::RenderWithoutMaterial(gfx::AnimatedModel *model, const gfx::AnimatedModelParams& params) { // Find or create render caching data for the model auto &renderData = mRenderDataCache[model->GetHandle()]; if (!renderData) { renderData = std::make_unique<AasRenderData>(); } auto materialIds(model->GetSubmeshes()); for (size_t i = 0; i < materialIds.size(); ++i) { auto submesh(model->GetSubmesh(params, i)); auto &submeshData = GetSubmeshData(*renderData, i, *submesh); submeshData.binding.Bind(); auto d3d = mDevice.GetDevice(); d3d->SetIndices(submeshData.idxBuffer->GetBuffer()); D3DLOG(d3d->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, submesh->GetVertexCount(), 0, submesh->GetPrimitiveCount())); } }
inline void RenderSystem::SetIndices(sIndexBuffer& indexBuffer) { SetIndices(indexBuffer.ib); }
void AasRenderer::Render(gfx::AnimatedModel *model, const gfx::AnimatedModelParams& params, gsl::span<Light3d> lights, const MdfRenderOverrides *materialOverrides) { // Find or create render caching data for the model auto &renderData = mRenderDataCache[model->GetHandle()]; if (!renderData) { renderData = std::make_unique<AasRenderData>(); } auto materialIds(model->GetSubmeshes()); for (size_t i = 0; i < materialIds.size(); ++i) { auto materialId = materialIds[i]; auto submesh(model->GetSubmesh(params, i)); // Remove special material marker in the upper byte and only // use the actual shader registration id materialId &= 0x00FFFFFF; // Usually this should not happen, since it means there's // an unbound replacement material if (materialId == 0) { continue; } // if material was not found if (materialId == 0x00FFFFFF) { continue; } auto material = mMdfFactory.GetById(materialId); if (!material) { logger->error("Legacy shader with id {} wasn't found.", materialId); continue; } material->Bind(mDevice, lights, materialOverrides); // Do we have to recalculate the normals? if (material->GetSpec()->recalculateNormals) { RecalcNormals( submesh->GetVertexCount(), submesh->GetPositions().data(), submesh->GetNormals().data(), submesh->GetPrimitiveCount(), submesh->GetIndices().data() ); } auto &submeshData = GetSubmeshData(*renderData, i, *submesh); submeshData.binding.Bind(); auto d3d = mDevice.GetDevice(); d3d->SetIndices(submeshData.idxBuffer->GetBuffer()); D3DLOG(d3d->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, submesh->GetVertexCount(), 0, submesh->GetPrimitiveCount())); } }
void TerrainRenderablePlane::Render(HippoD3d9Device* pdevice, unsigned int escapeTime) { auto d3d9device = pdevice->GetDeviceD3D9(); //d3d9device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); //world matrix D3DXMATRIX tmpMatrix; D3DXMatrixMultiply(&tmpMatrix, &m_local_matrix, m_parent->GetWorldTransform()); HRESULT v = m_fxhandle->SetMatrix("g_mWorld", &tmpMatrix); //wvp matrix auto proj = Globals::GetRender()->GetProjMatrix(); auto view = Globals::GetRender()->GetViewMatrix(); D3DXMATRIX vp = (*view)*(*proj); v = m_fxhandle->SetMatrix("g_mViewProjection", &vp); //camera const D3DXVECTOR3* pos = Globals::GetCurrentCamera()->GetPos(); v = m_fxhandle->SetValue("g_camera_pos", pos, sizeof(D3DXVECTOR3)); //material D3DXCOLOR vWhite = D3DXCOLOR(0.5, 0.3, 0.2, 1); v = m_fxhandle->SetValue("g_MaterialDiffuseColor", &vWhite, sizeof(D3DXCOLOR)); //texture v = m_fxhandle->SetTexture("g_MeshTexture", m_pTextrue[0]); //tower info auto alltowers = Globals::GetWorld()->GetAllTower(); auto itr = alltowers.begin(); D3DXVECTOR4 tmp[2]; int idx = 0; while (itr != alltowers.end()) { TowerEntity* pEntity = (TowerEntity*)((*itr).get()); D3DXVECTOR3* pos = pEntity->GetPos(); float r = pEntity->GetRange(); tmp[idx] = D3DXVECTOR4(pos->x, pos->y, pos->z, r); ++itr; ++idx; } v = m_fxhandle->SetVectorArray("towerInfo", tmp, 2); //robot info auto player = Globals::GetWorld()->GetPlayer(); pos = player->GetPos(); D3DXVECTOR4 robotpos = D3DXVECTOR4(pos->x, pos->z, 12.f, 1.0f); v = m_fxhandle->SetVector("robotInfo", &robotpos); d3d9device->SetStreamSource(0, m_pVB, 0, sizeof(TerrainVertex)); d3d9device->SetVertexDeclaration(m_pVertexDecl); d3d9device->SetIndices(m_pIB); UINT iPass, totalPasses; m_fxhandle->Begin(&totalPasses, 0); for (iPass = 0; iPass < totalPasses; iPass++) { m_fxhandle->BeginPass(iPass); d3d9device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, // 将要绘制的索引缓冲区的起始地址 0, // 索引数组中最小的索引值 GetVertexNum(), // 要绘制的索引数组中的顶点数量 0, // 从索引数组中的第几个元素开始绘制图元 GetTriangleNum()); // 绘制的图元数量 m_fxhandle->EndPass(); } m_fxhandle->End(); m_border_renderable->Render(pdevice, escapeTime); }
void TerrainRenderable::Render(HippoD3d9Device* pdevice, unsigned int escapeTime) { auto d3d9device = pdevice->GetDeviceD3D9(); //*d3d9device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);*/ //world matrix D3DXMATRIX tmpMatrix; D3DXMatrixMultiply(&tmpMatrix, &m_local_matrix, m_parent->GetWorldTransform()); HRESULT v = m_fxhandle->SetMatrix("g_mWorld", &tmpMatrix); //wvp matrix auto proj = Globals::GetRender()->GetProjMatrix(); auto view = Globals::GetRender()->GetViewMatrix(); D3DXMATRIX vp = (*view)*(*proj); v = m_fxhandle->SetMatrix("g_mViewProjection", &vp); //camera const D3DXVECTOR3* pos=Globals::GetCurrentCamera()->GetPos(); v = m_fxhandle->SetValue("g_camera_pos", pos, sizeof(D3DXVECTOR3)); //texture v = m_fxhandle->SetTexture("g_DiffuseTex", m_pTextrue[0]); v = m_fxhandle->SetTexture("g_DetailTex", m_pTextrue[1]); v = m_fxhandle->SetTexture("g_NormalTex", m_pTextrue[2]); //tower info const GameEntityPtrCon& con = Globals::GetWorld()->GetAllTower(); GameEntityPtrCon::const_iterator itr = con.begin(); GameEntityPtrCon::const_iterator itrend = con.end(); D3DXVECTOR4 tmp[2]; int idx = 0; while (itr != itrend) { auto towerptr = (TowerEntity*)itr->get(); D3DXVECTOR3* pos = towerptr->GetPos(); float r = towerptr->GetRange(); tmp[idx] = D3DXVECTOR4(pos->x, pos->y, pos->z, r); ++itr; ++idx; } v=m_fxhandle->SetVectorArray("towerInfo", tmp, 2); //robot info auto robot=Globals::GetWorld()->GetPlayer(); D3DXVECTOR4 robotpos = D3DXVECTOR4(robot->GetPos()->x, robot->GetPos()->z, 2, 1); v=m_fxhandle->SetVector("robotInfo", &robotpos); d3d9device->SetStreamSource(0, m_pVB, 0, sizeof(TerrainVertex)); d3d9device->SetVertexDeclaration(m_pVertexDecl); d3d9device->SetIndices(m_pIB); UINT iPass, totalPasses; m_fxhandle->Begin(&totalPasses, 0); for (iPass = 0; iPass < totalPasses; iPass++) { m_fxhandle->BeginPass(iPass); //d3d9device->DrawPrimitive(D3DPT_POINTLIST, // 0, // 将要绘制的索引缓冲区的起始地址 // GetVertexNum()); // 绘制的图元数量 d3d9device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, // 将要绘制的索引缓冲区的起始地址 0, // 索引数组中最小的索引值 GetVertexNum(), // 要绘制的索引数组中的顶点数量 0, // 从索引数组中的第几个元素开始绘制图元 GetTriangleNum()); // 绘制的图元数量 m_fxhandle->EndPass(); } m_fxhandle->End(); return; //patch auto pthitr = m_all_patch.begin(); while (pthitr != m_all_patch.end()) { auto patch_fx = (*pthitr)->GetPatchFx(); auto patch_ib = (*pthitr)->GetIB(); int tri_count = (*pthitr)->GetIndexCount() / 3; d3d9device->SetStreamSource(0, m_pVB, 0, sizeof(TerrainVertex)); d3d9device->SetVertexDeclaration(m_pVertexDecl); HRESULT v = d3d9device->SetIndices(patch_ib); v=patch_fx->SetMatrix("g_mWorld", &tmpMatrix); v = patch_fx->SetMatrix("g_mViewProjection", &vp); v = patch_fx->SetValue("g_camera_pos", pos, sizeof(D3DXVECTOR3)); UINT totalPasses; v=patch_fx->Begin(&totalPasses, 0); v = patch_fx->BeginPass(0); v = d3d9device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, // 将要绘制的索引缓冲区的起始地址 0, // 索引数组中最小的索引值 GetVertexNum(), // 要绘制的索引数组中的顶点数量 0, // 从索引数组中的第几个元素开始绘制图元 tri_count); // 绘制的图元数量 v = patch_fx->EndPass(); ++pthitr; } }
DataRepresentation::DataRepresentation(size_t index_){ SetIndices(std::vector<size_t>(1, index_)); }
DataRepresentation::DataRepresentation(const std::vector<size_t>& indices_){ SetIndices(indices_); }
DataRepresentation::DataRepresentation(const DataRepresentation& other_){ fName = other_.fName; SetIndices(other_.fIndices); }
void TextShape::SetText(std::string& _text) { Font* _font = m_font; natBool doAllocate = false; if(_text.size() > m_bufferAllocated) { doAllocate = true; } m_text = _text; m_font = _font; size_t text_size = m_text.size(); size_t vertex_size = text_size * 4 * 4; size_t color_size = text_size * 4 * 4; size_t uv_size = text_size * 4 * 2; m_colorOffset = vertex_size; m_uvOffset = vertex_size + color_size; m_vertexNumber = static_cast<natU32>(text_size * 4); m_indicesNumber = (m_vertexNumber / 4) * 6; m_length = vertex_size + color_size + uv_size; if(doAllocate) { if(m_vertex) { delete [] m_vertex; m_vertex = nullptr; } if(m_indices) { delete [] m_indices; m_indices = nullptr; } assert(m_vertex == nullptr); assert(m_indices == nullptr); m_vertex = new natF32[m_length]; m_indices = new natU16[m_indicesNumber]; m_bufferAllocated = m_text.size(); } assert(m_vertex); assert(m_indices); //memset(m_vertex, 0, m_length); for(size_t index=0; index < m_length; ++index) { m_vertex[index] = 0.f; } natU32 advance = 0; natU32 i = 0; std::string::iterator c = m_text.begin(); std::string::iterator const tmp_end = m_text.end(); Font::char_info_t* ci; // Fill vertex data for(; c != tmp_end; ++c) { ci = &m_font->m_info.ch[*c]; m_vertex[i+0] = ci->left+advance+ci->v[1].x; m_vertex[i+1] = ci->v[1].y + (m_font->m_info.max_height-ci->top); m_vertex[i+4] = ci->left+advance+ci->v[2].x; m_vertex[i+5] = ci->v[2].y + (m_font->m_info.max_height-ci->top); m_vertex[i+8] = ci->left+advance+ci->v[0].x; m_vertex[i+9] = ci->v[0].y + (m_font->m_info.max_height-ci->top); m_vertex[i+12] = ci->left+advance+ci->v[3].x; m_vertex[i+13] = ci->v[3].y + (m_font->m_info.max_height-ci->top); m_vertex[i+3] = 1.f; m_vertex[i+7] = 1.f; m_vertex[i+11] = 1.f; m_vertex[i+15] = 1.f; advance += ci->advance; i+=(4*4); m_size.x += static_cast<natF32>(ci->width); m_size.y = static_cast<natF32>(ci->height); } // Fill UV data natF32* uv = m_vertex + vertex_size + color_size; i = 0; c = m_text.begin(); for(; c != tmp_end; ++c) { ci = &m_font->m_info.ch[*c]; uv[i+0] = ci->uv[1].x; uv[i+1] = ci->uv[1].y; uv[i+2] = ci->uv[2].x; uv[i+3] = ci->uv[2].y; uv[i+4] = ci->uv[0].x; uv[i+5] = ci->uv[0].y; uv[i+6] = ci->uv[3].x; uv[i+7] = ci->uv[3].y; i+=(4*2); } SetColor(m_color); SetIndices(); m_isDirty = true; }