Exemple #1
0
bool Dlite::ComputeShortestPath(LocalMap &map)
{
    while (OPEN.top_key_less_than(CalculateKey(*start)) || start->rhs != start->g) {
        ++number_of_steps;
        Node* current = OPEN.get();\
        Key old_key = current->key;
        Key new_key = CalculateKey(*current);
        if (old_key < new_key) {
            current->key = new_key;
            OPEN.put(current);
        } else if (current->g > current->rhs) {
            current->g = current->rhs;
            OPEN.pop();
            for (auto elem : GetSuccessors(current, map)) {
                if (elem->point != map.goal && elem->rhs > current->g + GetCost(elem->point, current->point, map)) {
                    elem->parent = current;
                    elem->rhs = current->g + GetCost(elem->point, current->point, map);
                }
                UpdateVertex(elem); // !!!<-apparently OK
            }
        } else {
            //double old_g = current->g;
            current->g = std::numeric_limits<double>::infinity();
            std::vector<Node* > succ = GetSuccessors(current, map);
            succ.push_back(current);
            for (auto elem : succ) {
                if (elem->point != map.goal && elem->parent->point == current->point) {
                    Node min_val = GetMinPredecessor(elem, map);
                    elem->rhs = min_val.rhs;
                    if(min_val.parent)
                        elem->parent = min_val.parent;
                }
                UpdateVertex(elem);
            }
        }
        /*if(current->parent) {
            std::cout << current->point << "g " << current->g << " rhs" << current->rhs <<
                  current->parent->point << std::endl;
        }  */   //std::cout << OPEN.top_key().k1 << std::endl;
        //OPEN.print_elements();

    }
    if (start->rhs != std::numeric_limits<double>::infinity()) {
        current_result.pathfound = true;
        current_result.numberofsteps = number_of_steps;
        current_result.nodescreated = NODES.size();
        //std::cout << start->rhs << std::endl;
        //MakePrimaryPath(start);
        //current_result.lppath = &path;
        //map.PrintPath(curpath);
        //for (auto elem : curpath) path.push_back(elem);
        return true;
    } else {
        current_result.pathfound = false;
        current_result.pathlength = 0;
        return false;
    }
    return false;
}
Exemple #2
0
	void SpriteBase::OnUpdate() {
		float ElapsedTime = App::GetApp()->GetElapsedTime();
		auto Dev = App::GetApp()->GetDeviceResources();
		auto pD3D11DeviceContext = Dev->GetD3DDeviceContext();
		//頂点の変更
		//D3D11_MAP_WRITE_DISCARDは重要。この処理により、GPUに邪魔されない
		D3D11_MAP mapType = D3D11_MAP_WRITE_DISCARD;
		D3D11_MAPPED_SUBRESOURCE mappedBuffer;
		//頂点のマップ
		if (FAILED(pD3D11DeviceContext->Map(m_SquareMesh->GetVertexBuffer().Get(), 0, mapType, 0, &mappedBuffer))) {
			// Map失敗
			throw BaseException(
				L"頂点のMapに失敗しました。",
				L"if(FAILED(pID3D11DeviceContext->Map()))",
				L"WrappedSprite::UpdateVertex()"
			);
		}
		//頂点の変更
		VertexPositionColorTexture* vertices
			= (VertexPositionColorTexture*)mappedBuffer.pData;
		//仮想関数呼び出し
		UpdateVertex(ElapsedTime, vertices);
		//アンマップ
		pD3D11DeviceContext->Unmap(m_SquareMesh->GetVertexBuffer().Get(), 0);
	}
Exemple #3
0
void CBillBoardAni::Update(D3DXVECTOR3 camera_pos)
{
	UpdateVertex();

	if(!m_changeByCamera)
	{
		//SetMatrix();
		return;
	}
	CBillboard::Update(camera_pos);
}
void RenderData::Bind(){
    DisplayGlError("Pre bind");
    #ifdef SUPPORT_SINGLE_BUFFER
    VertexBuffer = Painter::GetSharedBuffer(0);
    ElementBuffer = Painter::GetSharedBuffer(1);
    #endif
    DisplayGlError("Binding");
    UpdateVertex();
    glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer);
}
	void Sprite::Draw(ID3D12GraphicsCommandList* commandList){
		SetVertexPos(vertex, pos, base, size, angle);
		UpdateVertex(vertex.data(),vertexResource.get());
		SetConstantBuffer(commandList);
		DX12::SetTexture(commandList,fileName);
		
		UINT SizeTbl[] = { sizeof(DefaultVertex) };
		UINT OffsetTbl[] = { 0 };
		commandList->IASetVertexBuffers(0, 1, &vertexBufferView);
		commandList->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);

		commandList->DrawInstanced(4, 1, 0, 0);
	}
Exemple #6
0
	long SmtWater::Create(LP3DRENDERDEVICE p3DRenderDevice)
	{
		if (NULL == p3DRenderDevice)
		{
			return SMT_ERR_INVALID_PARAM;
		}

		m_pVertexBuffer = p3DRenderDevice->CreateVertexBuffer(2*(CST_INT_GRID_HEIGHT-1) * CST_INT_GRID_WIDTH,VF_XYZ|VF_DIFFUSE| VF_NORMAL|VF_TEXCOORD,false);
	
		m_aAbb.vcMax.Set(0,0,0);
		m_aAbb.vcMin.Set(0,0,0);
		m_aAbb.vcMax += (CST_INT_GRID_HEIGHT/2.)*m_fXScale;
		m_aAbb.vcMin += -(CST_INT_GRID_HEIGHT/2.)*m_fZScale;
		m_aAbb.vcCenter += (m_aAbb.vcMax+m_aAbb.vcMin)/2.;

		return SMT_ERR_NONE;
		//////////////////////////////////////////////////////////////////////////
		int x,y,index = 0;	
		double dx, dy, d;

		for(y = 0; y<CST_INT_GRID_HEIGHT; y++)
		{
			for(x = 0; x<CST_INT_GRID_WIDTH; x++)
			{
				dx = (double)(x-CST_INT_GRID_WIDTH/2);
				dy = (double)(y-CST_INT_GRID_HEIGHT/2);
				d = sqrt( dx*dx + dy*dy );
				if(d < 0.1 * (double)(CST_INT_GRID_WIDTH/2))
				{
					d = d * 10.0;
					p[x][y] = -cos(d * (PI / (double)(CST_INT_GRID_WIDTH * 4))) * 100.0;
				}
				else
				{
					p[x][y] = 0.0;
				}
				vx[x][y] = 0.0;
				vy[x][y] = 0.0;
			}
		}

		UpdateVertex();
		UpdateNormal();
		UpdateTexcoord();
		//
		UpdateVB();

		return SMT_ERR_NONE;
	}
Exemple #7
0
	void SimpleSquare::OnUpdate() {
		float ElapsedTime = App::GetApp()->GetElapsedTime();
		auto Dev = App::GetApp()->GetDeviceResources();
		auto pD3D11DeviceContext = Dev->GetD3DDeviceContext();
		//頂点の変更
		//D3D11_MAP_WRITE_DISCARDは重要。この処理により、GPUに邪魔されない
		D3D11_MAP mapType = D3D11_MAP_WRITE_DISCARD;
		D3D11_MAPPED_SUBRESOURCE mappedBuffer;
		//頂点のマップ
		if (FAILED(pD3D11DeviceContext->Map(m_SquareMesh->GetVertexBuffer().Get(), 0, mapType, 0, &mappedBuffer))) {
			// Map失敗
			throw BaseException(
				L"頂点のMapに失敗しました。",
				L"if(FAILED(pID3D11DeviceContext->Map()))",
				L"SimpleSquare::OnUpdate()"
			);
		}
		//頂点の変更
		VertexPositionColorTexture* vertices
			= (VertexPositionColorTexture*)mappedBuffer.pData;
		//関数呼び出し
		UpdateVertex(ElapsedTime, vertices);
		//アンマップ
		pD3D11DeviceContext->Unmap(m_SquareMesh->GetVertexBuffer().Get(), 0);


		auto PtrStage = GetStage<Stage>();
		//カメラの位置
		Vec3 CameraEye = PtrStage->GetCamera().m_CamerEye;
		Vec3 CameraAt = PtrStage->GetCamera().m_CamerAt;
		switch (m_DrawOption) {
		case SquareDrawOption::Billboard:
		{
			m_Qt.facing(CameraAt - CameraEye);
		}
		break;
		case SquareDrawOption::Faceing:
		{
			m_Qt.facing(m_Pos - CameraEye);
		}
		break;
		case SquareDrawOption::FaceingY:
			m_Qt.facingY(m_Pos - CameraEye);
			break;
		default:
			m_Qt.normalize();
			break;
		}
	}
Exemple #8
0
	long SmtWater::Init(Vector3& vPos,SmtMaterial&matMaterial,const char* szTexName)
	{
		Smt3DObject::Init(vPos,matMaterial,szTexName);

		m_fTexOffset = 0;

		//////////////////////////////////////////////////////////////////////////
		int x,y,index = 0;	
		/* place the vertices in a grid */
		for(y=0;y<CST_INT_GRID_HEIGHT;y++)
			for(x=0;x<CST_INT_GRID_WIDTH;x++)
			{
				index = y*CST_INT_GRID_WIDTH + x;
				wvertex[index].x = (x-CST_INT_GRID_WIDTH/2)*m_fXScale;
				wvertex[index].y = (y-CST_INT_GRID_HEIGHT/2)*m_fZScale;
				wvertex[index].z = 0;
				wvertex[index].r = 0.7;
				wvertex[index].g = 0.8;
				wvertex[index].b = 0.7;
				wvertex[index].u = y;
				wvertex[index].v = x;
			}

		//////////////////////////////////////////////////////////////////////////
		for(y = 0; y<CST_INT_GRID_HEIGHT; y++)
		{
			for(x = 0; x<CST_INT_GRID_WIDTH; x++)
			{
				p[x][y] = 0.0;
				vx[x][y] = 0.0;
				vy[x][y] = 0.0;
			}
		}

		UpdateVertex();
		UpdateNormal();

		UpdateTexcoord();

		return SMT_ERR_NONE;
	}
void RenderData::SetPosition(Point pos){
    position = pos;
    UpdateVertex();
}
Exemple #10
0
SearchResult Dlite::FindThePath(LocalMap &map, const Map& const_map, EnvironmentOptions options)
{
    opt = options;
    std::chrono::time_point<std::chrono::system_clock> tstart, end;
    tstart = std::chrono::system_clock::now();
    number_of_steps = 0;
    current_result.pathlength = 0;
    Initialize(map);
    last = start;

    if(!ComputeShortestPath(map))
        std::cout << "OOOPS\n";
    else
        std::cout << "Done\n";
    std::cout << current_result.pathlength <<std::endl;
    while(start->point != goal->point) {
        Cell jump = start->point;
        Node min_val = GetMinPredecessor(start, map);
        path.push_back(*start);
        if (!min_val.parent) {
            OPEN.remove_if(start);
            current_result.pathfound = false;
            current_result.pathlength = 0;
            return current_result;
        } else {
            current_result.pathlength += GetCost(start->point, min_val.parent->point, map);
            start = min_val.parent;
        }
        min_val = GetMinPredecessor(start, map);
        while (opt.allowjump && euclid_dist(jump, min_val.parent->point) < radius && start->point != goal->point) {
            path.push_back(*start);
            if (!min_val.parent) {
                OPEN.remove_if(start);
                current_result.pathfound = false;
                current_result.pathlength = 0;
                return current_result;
            } else {
                current_result.pathlength += GetCost(start->point, min_val.parent->point, map);
                start = min_val.parent;
            }
            min_val = GetMinPredecessor(start, map);
        }
        UpdateVertex(start);
        Changes changes = map.UpdateMap(const_map, start->point, radius);
        if (!changes.cleared.empty() && !changes.occupied.empty()) {
            Km += heuristic(last->point, start->point, opt.metrictype);
            last = start;
        }
        for (auto dam : changes.occupied) {
            if (NODES.count(vertex(dam, map.height))) {
                Node* d = &(NODES.find(vertex(dam, map.height))->second);
                OPEN.remove_if(d);
                for (auto neighbor: GetSurroundings(d, map)) {
                    //std::cout << "n: " << neighbor->point << std::endl;
                    if (neighbor->point != map.goal && (neighbor->parent->point == dam || CutOrSqueeze(neighbor, d))) {
                        Node min_val = GetMinPredecessor(neighbor, map);
                        if (!min_val.parent) {
                            OPEN.remove_if(neighbor);
                            if(neighbor->point == start->point) {
                                current_result.pathfound = false;
                                current_result.pathlength = 0;
                                return current_result;
                            }
                        } else {
                            neighbor->rhs = min_val.rhs;
                            neighbor->parent = min_val.parent;
                           // std::cout << "changed: "
                             //         << neighbor->point << ' ' << neighbor->parent->point << std::endl;
                            UpdateVertex(neighbor);
                        }
                    }
                }
            }
        }
        for (auto cleared : changes.cleared) {
           Node new_node(cleared);
           new_node.rhs = std::numeric_limits<double>::infinity();
           new_node.g = std::numeric_limits<double>::infinity();
           NODES[vertex(cleared, map.height)] = new_node;
           Node * cl = &(NODES.find(vertex(cleared, map.height))->second);
           Node min_val = GetMinPredecessor(cl, map);
           if (min_val.parent) {
               cl->rhs = min_val.rhs;
               cl->parent = min_val.parent;
               cl->g = min_val.parent->g + GetCost(cl->point, min_val.parent->point, map);
               UpdateVertex(cl);
           } else {
               break;
           }
           for (auto neighbor : GetSuccessors(cl, map)) {
               if (neighbor->rhs > cl->g + GetCost(neighbor->point, cl->point, map)) {
                   neighbor->parent = cl;
                   neighbor->rhs = cl->g + GetCost(neighbor->point, cl->point, map);
                   UpdateVertex(neighbor);
               }
               if (neighbor->point.x == cl->point.x || neighbor->point.y == cl->point.y) {
                   Node min_val = GetMinPredecessor(neighbor, map);
                   if (!min_val.parent) {
                       OPEN.remove_if(neighbor);
                       if(neighbor->point == start->point) {
                           current_result.pathfound = false;
                           current_result.pathlength = 0;
                           return current_result;
                       }
                   } else {
                       neighbor->rhs = min_val.rhs;
                       neighbor->parent = min_val.parent;
                       //std::cout << "changed: "
                       //          << neighbor->point << ' ' << neighbor->parent->point << std::endl;
                       UpdateVertex(neighbor);
                   }
               }
           }
        }
        if(ComputeShortestPath(map)){
            //std::cout << "ALL OK\n";
            continue;
        } else {
            std::cout << "NOT OK"  << std::endl;
            if (OPEN.top_key() == Key(std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity())) {
                current_result.pathfound = false;
                current_result.pathlength = 0;
                break;
            }
        }
    }
    end = std::chrono::system_clock::now();
    current_result.time = static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(end - tstart).count()) / 1000000000;
    //map.PrintPath(path);
    current_result.lppath = &path;
    if (current_result.pathfound) {
        makeSecondaryPath();
        current_result.hppath = &hpath;
    }
    //for (auto elem: path) std::cout << elem->point << " ";
    //std::cout << std::endl;
    return current_result;
}