Archive 17/01/2023.

Currently working on geometry shape protrusion, circle and sphere generator code

codexhound

Needed some of it for my project and I thought it would be good to have some easy functions to create simple geometry.

Heres a sample of protruding a circle and making a cone:

And an example of a sphere:

           Some Example Code:
                   void CustomGeometry::ProtrudeShape(const std::vector<Vector3>& mShapeList, const                std::vector<Vector3>& mPointList)
       {
Vector3 centerPoint = Urho3D::Average<Urho3D::Vector3>(mShapeList);
Vector3 pointCurrent;
Vector3 shapeCurrent;
Vector3 shapePointVec;
Vector3 shapePointDir;
Vector3 pointLast;
std::vector<Vector3> mPointBuffer(mShapeList.size()*mPointList.size()+mShapeList.size());

std::vector<Vector3> mLastShapePos = mShapeList;
auto pointIter = mPointList.begin();
auto shapeIter = mLastShapePos.begin();

int bufferCount = 0;
while (shapeIter != mLastShapePos.end()) {
    mPointBuffer.at(bufferCount) = (*shapeIter);
    shapeIter++;
    bufferCount++;
}


int count = 0;
while (pointIter != mPointList.end()) {
    shapeIter = mLastShapePos.begin();
    pointCurrent = (*pointIter);
    count = 0;
    while (shapeIter != mLastShapePos.end()) {
        shapeCurrent = (*shapeIter);
        if (shapeIter == mLastShapePos.begin()) { //protrude from first point of the shape and create dir Vector to point
            shapePointVec = pointCurrent - centerPoint;
            centerPoint = pointCurrent;
        }
        // protrude from the rest of the points on the shape to the next point given a dir and length vector
        shapePointDir = shapePointVec;
        shapePointDir.Normalize();
        mLastShapePos[count] = mLastShapePos[count] + shapePointDir * shapePointVec.Length();
        mPointBuffer.at(bufferCount) = mLastShapePos[count];

        bufferCount++;
        shapeIter++;
        count++;
    }
    pointIter++;
}
CreateQuadsFromBuffer(mPointBuffer, mShapeList.size(), mPointList.size()+1);