void CBezierPatch::BuildBezierPoints_Sub2() { // return; // int nSubdivisionLevel = GetSettings()->GetNofSubdivisions(); int nN = 3; for (int l = nN; l >= 0; --l) { for (int m = 0; m <= l; ++m) { int u = l-m; int v = m; int w = nN - l; Point(u, v) = CalculateBezierPoint(u, v, w); } } BuildBezierPoints_Internal(); }
void FollowPathComponent::Update(float time) { if(m_delayed) { // If delayed, increment current delay time. Then check if it's ready to go on to the next // node. If it is, get the next node. m_currentDelayTime += time; if(m_currentDelayTime > m_nodes[m_nextNode].delay) { m_currentDelayTime = 0.0f; m_delayed = false; GetNextNode(); // Now get the next destination. } return; } if(m_nodes.size() > m_nextNode) { m_t += time; float t = m_t / m_nodes[m_nextNode].timeToReach; glm::vec3 nextPoint; glm::vec3 refPoint; if(m_reverse) { nextPoint = CalculateBezierPoint(t, m_nodes[m_nextNode+3].position, // p0 m_nodes[m_nextNode+2].position, // p1 m_nodes[m_nextNode+1].position, // p2 m_nodes[m_nextNode].position); // p3 refPoint = CalculateBezierPoint(t+0.05f, m_nodes[m_nextNode+3].position, // p0 m_nodes[m_nextNode+2].position, // p1 m_nodes[m_nextNode+1].position, // p2 m_nodes[m_nextNode].position); // p3 } else { nextPoint = CalculateBezierPoint(t, m_nodes[m_nextNode-3].position, // p0 m_nodes[m_nextNode-2].position, // p1 m_nodes[m_nextNode-1].position, // p2 m_nodes[m_nextNode].position); // p3 refPoint = CalculateBezierPoint(t+0.05f, m_nodes[m_nextNode-3].position, // p0 m_nodes[m_nextNode-2].position, // p1 m_nodes[m_nextNode-1].position, // p2 m_nodes[m_nextNode].position); // p3 } glm::vec3 a = GetParent().GetTransform().GetForward(); glm::vec3 b = refPoint - GetParent().GetPos(); float cosX = glm::dot(a, b); cosX = cosX / (glm::length(a) * glm::length(b)); float x = glm::acos(glm::max(glm::min(cosX, 1.0f), -1.0f)); // Not sure if need to convert cosX to radians. x = x * 10.0f; glm::vec3 rotationAxis = glm::normalize(glm::cross(a, b)); Frame transform = GetParent().GetTransform(); glm::vec3 currUp = glm::normalize(transform.GetUp()); glm::vec3 currForward = glm::normalize(transform.GetForward()); glm::vec3 newForward = glm::rotate(currForward, x, rotationAxis); transform.SetForward(glm::normalize(newForward)); glm::vec3 newUp = glm::rotate(currUp, x, rotationAxis); transform.SetUp(glm::normalize(newUp)); GetParent().SetTransform(transform); GetParent().SetPos(nextPoint); if(t >= 1.0f) { // Arrived at node. Now check if there is a delay on it before getting next destination. if(m_nodes[m_nextNode].delay > 0.0001f) { m_delayed = true; m_currentDelayTime = 0.0f; } else { GetNextNode(); } m_t = 0.0f; } } }
void FollowPathComponent::InitDebugBuffers(D3D& d3d) { std::vector<glm::vec3> vertices; // Create the vertices for the path. for(int i = 0; i < m_nodes.size() - 3; i += 3) { if((i + 3) < m_nodes.size()) { for(int t = 0; t < 21; t++) { float ft = t / 20.0f; vertices.push_back(CalculateBezierPoint(ft, m_nodes[i].position, m_nodes[i+1].position, m_nodes[i+2].position, m_nodes[i+3].position)); } /* for(float t = 0.0f; t < 1.001f; t+= 0.05f) { vertices.push_back(CalculateBezierPoint(t, m_nodes[i].position, m_nodes[i+1].position, m_nodes[i+2].position, m_nodes[i+3].position)); }*/ } } m_indexNum = vertices.size(); unsigned long* indices = new unsigned long[m_indexNum]; for(int i = 0; i < m_indexNum; i++) { indices[i] = i; } D3D11_BUFFER_DESC vertexBufferDesc = { sizeof(glm::vec3) * m_indexNum, // ByteWidth D3D11_USAGE_DEFAULT, // Usage D3D11_BIND_VERTEX_BUFFER, // BindFlags 0, // CPUAccessFlags 0, // MiscFlags 0 // StructureByteStride }; D3D11_SUBRESOURCE_DATA vertexData = { &vertices[0], // pSysMem 0, // SysMemPitch 0, // SysMemSlicePitch }; HRESULT hr = d3d.GetDevice().CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer); if(FAILED(hr)) { delete[] indices; indices = 0; return; } D3D11_BUFFER_DESC indexBufferDesc = { sizeof(unsigned long) * m_indexNum, // ByteWidth D3D11_USAGE_DEFAULT, // Usage D3D11_BIND_INDEX_BUFFER, // BindFlags 0, // CPUAccessFlags 0, // MiscFlags 0 }; D3D11_SUBRESOURCE_DATA indexData = { indices, // pSysMem 0, // SysMemPitch 0 // SysMemSlicePitch }; hr = d3d.GetDevice().CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer); if(FAILED(hr)) { delete[] indices; indices = 0; return; } delete[] indices; indices = 0; }