static SMeshBuffer* createQuad(f32 size, float z) { u32 i; SMeshBuffer *buffer = new SMeshBuffer(); const u16 u[6] = { 0,1,2, 0,3,1}; buffer->cnt_indices = 6; buffer->indices = (u16*)rsxMemalign(128, buffer->cnt_indices * sizeof(u16)); for(i = 0; i < 6; i++) buffer->indices[i] = u[i]; buffer->cnt_vertices = 4; buffer->vertices = (S3DVertex*)rsxMemalign(128, buffer->cnt_vertices * sizeof(S3DVertex)); // position, normal, texture buffer->vertices[0] = S3DVertex(0, -1, z, 0, 0, -1, 0, 1); buffer->vertices[1] = S3DVertex(1, 0, z, 0, 0, -1, 1, 0); buffer->vertices[2] = S3DVertex(0, 0, z, 0, 0, -1, 0, 0); buffer->vertices[3] = S3DVertex(1, -1, z, 0, 0, -1, 1, 1); //centre and resize for(i=0; i < 4; i++) { //center buffer->vertices[i].pos += Vector3(-0.5f, 0.5f, 0.0f); //resize buffer->vertices[i].pos *= size; } return buffer; }
CSampleSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id, vector3df p1, vector3df p2, vector3df p3, vector3df p4 ) : ISceneNode(parent, mgr, id) { Material.Wireframe = false; Material.Lighting = false; Vertices[0] = S3DVertex(p1.X, p1.Y, p1.Z, 1, 1,-1, SColor(255,255,255,255), 1, 0); Vertices[1] = S3DVertex(p2.X, p2.Y, p2.Z, 1, 1, 1, SColor(255,255,255,255), 0, 0); Vertices[2] = S3DVertex(p3.X, p3.Y, p3.Z, -1, 1, 1, SColor(255,255,255,255), 0, 1); Vertices[3] = S3DVertex(p4.X, p4.Y, p4.Z, -1, 1,-1, SColor(255,255,255,255), 1, 1); }
CSampleSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id) : ISceneNode(parent, mgr, id) { Material.Wireframe = false; Material.Lighting = false; Vertices[0] = S3DVertex(0, 0, 10, 1, 1, 0, SColor(255, 0, 255, 255), 0, 1); Vertices[1] = S3DVertex(10, 0, -10, 1, 0, 0, SColor(255, 255, 0, 255), 1, 1); Vertices[2] = S3DVertex(0, 20, 0, 0, 1, 1, SColor(255, 255, 255, 0), 1, 0); Vertices[3] = S3DVertex(-10, 0, -10, 0, 0, 1, SColor(255, 0, 255, 0), 0, 0); Box.reset(Vertices[0].Pos); for (s32 i = 1; i < 4; ++i) Box.addInternalPoint(Vertices[i].Pos); }
void PathDrawableObject::UpdatePath(Vector3 pos) { if (drawPath) { if (currentFrame >= numFrames) { currentPosition = pos; S3DVertex tempVertex = S3DVertex(pos, Vector3_Zero, color, vector2d<float>(0.0f, 0.0f)); pathVertices.push_back(tempVertex); if (currentIndex != 0) { pathIndicies.push_back(currentIndex - 1); pathIndicies.push_back(currentIndex); } currentIndex++; currentFrame = 0; } else { /*if (currentFrame >= numFrames) { currentFrame = 0; } else*/ { currentFrame++; } } } }
void Materials::GenArrow(float y) { float ay = 1.0f; for (int i = 0; i < 19; ++i) { vArrow[i * 2] = S3DVertex(vector3df(0.1f, ay * y, -2.0f * (ay * ay - 1.0f)), vector3df(0, ay * y, 1), 0xc000ff00, vector2df(0, 0)); vArrow[i * 2 + 1] = S3DVertex(vector3df(-0.1f, ay * y, -2.0f * (ay * ay - 1.0f)), vector3df(0, ay * y, 1), 0xc000ff00, vector2df(0, 0)); ay -= 0.1f; } vArrow[36].Pos.X = 0.2f; vArrow[36].Pos.Y = vArrow[34].Pos.Y - 0.01f; vArrow[36].Pos.Z = vArrow[34].Pos.Z - 0.01f; vArrow[37].Pos.X = -0.2f; vArrow[37].Pos.Y = vArrow[35].Pos.Y - 0.01f; vArrow[37].Pos.Z = vArrow[35].Pos.Z - 0.01f; vArrow[38] = S3DVertex(vector3df(0.0f, -1.0f * y, 0.0f), vector3df(0.0f, -1.0f, -1.0f), 0xc0ffffff, vector2df(0, 0)); vArrow[39] = vArrow[38]; }
void VectorSimulation::AddVectorFunction(Vector3 vec) { Vector3 tail; Vector3 head; Vector3 arrowHead1; Vector3 arrowHead2; if(lineUpVectors) { tail = sumVector; } else { tail = Vector3(0.0f, 0.0f, 0.0f); } Get3DArrowPositions(tail, vec, head, arrowHead1, arrowHead2); S3DVertex tempVertex = S3DVertex(tail, Vector3(0.0f, 0.0f, 0.0f), vectorColor, vector2d<float>(0.0f, 0.0f)); arrowVertices.push_back(tempVertex); tempVertex.Pos = head; arrowVertices.push_back(tempVertex); tempVertex.Pos = arrowHead1; arrowVertices.push_back(tempVertex); tempVertex.Pos = arrowHead2; arrowVertices.push_back(tempVertex); arrowIndicies.push_back(numArrows*4 + 0); arrowIndicies.push_back(numArrows*4 + 1); arrowIndicies.push_back(numArrows*4 + 1); arrowIndicies.push_back(numArrows*4 + 2); arrowIndicies.push_back(numArrows*4 + 1); arrowIndicies.push_back(numArrows*4 + 3); numArrows++; AddToSumVector(vec); }
static SMeshBuffer* createCube(f32 size) { u32 i; SMeshBuffer *buffer = new SMeshBuffer(); const u16 u[36] = { 0,1,2, 0,2,3, 1,4,5, 1,5,2, 4,7,6, 4,6,5, 7,0,3, 7,3,6, 9,2,5, 9,5,8, 0,10,11, 0,7,10}; buffer->cnt_indices = 36; buffer->indices = (u16*)rsxMemalign(128,buffer->cnt_indices*sizeof(u16)); for(i=0;i<36;i++) buffer->indices[i] = u[i]; buffer->cnt_vertices = 12; buffer->vertices = (S3DVertex*)rsxMemalign(128,buffer->cnt_vertices*sizeof(S3DVertex)); buffer->vertices[0] = S3DVertex(0,0,0, -1,-1,-1, 1, 0); buffer->vertices[1] = S3DVertex(1,0,0, 1,-1,-1, 1, 1); buffer->vertices[2] = S3DVertex(1,1,0, 1, 1,-1, 0, 1); buffer->vertices[3] = S3DVertex(0,1,0, -1, 1,-1, 0, 0); buffer->vertices[4] = S3DVertex(1,0,1, 1,-1, 1, 1, 0); buffer->vertices[5] = S3DVertex(1,1,1, 1, 1, 1, 0, 0); buffer->vertices[6] = S3DVertex(0,1,1, -1, 1, 1, 0, 1); buffer->vertices[7] = S3DVertex(0,0,1, -1,-1, 1, 1, 1); buffer->vertices[8] = S3DVertex(0,1,1, -1, 1, 1, 1, 0); buffer->vertices[9] = S3DVertex(0,1,0, -1, 1,-1, 1, 1); buffer->vertices[10] = S3DVertex(1,0,1, 1,-1, 1, 0, 1); buffer->vertices[11] = S3DVertex(1,0,0, 1,-1,-1, 0, 0); for(i=0;i<12;i++) { buffer->vertices[i].pos -= Vector3(0.5f,0.5f,0.5f); buffer->vertices[i].pos *= size; } return buffer; }
static SMeshBuffer* createSphere(f32 radius,u32 polyCntX,u32 polyCntY) { u32 i,p1,p2,level; u32 x,y,polyCntXpitch; const f32 RECIPROCAL_PI = 1.0f/M_PI; SMeshBuffer *buffer = new SMeshBuffer(); if(polyCntX<2) polyCntX = 2; if(polyCntY<2) polyCntY = 2; if(polyCntX*polyCntY>32767) { if(polyCntX>polyCntY) polyCntX = 32767/polyCntY-1; else polyCntY = 32767/(polyCntX+1); } polyCntXpitch = polyCntX+1; buffer->cnt_vertices = (polyCntXpitch*polyCntY)+2; buffer->vertices = (S3DVertex*)rsxMemalign(128,buffer->cnt_vertices*sizeof(S3DVertex)); buffer->cnt_indices = (polyCntX*polyCntY)*6; buffer->indices = (u16*)rsxMemalign(128,buffer->cnt_indices*sizeof(u16)); i = 0; level = 0; for(p1=0;p1<polyCntY-1;p1++) { for(p2=0;p2<polyCntX-1;p2++) { const u32 curr = level + p2; buffer->indices[i++] = curr; buffer->indices[i++] = curr + polyCntXpitch; buffer->indices[i++] = curr + 1 + polyCntXpitch; buffer->indices[i++] = curr; buffer->indices[i++] = curr + 1 + polyCntXpitch; buffer->indices[i++] = curr + 1; } buffer->indices[i++] = level + polyCntX; buffer->indices[i++] = level + polyCntX - 1; buffer->indices[i++] = level + polyCntX - 1 + polyCntXpitch; buffer->indices[i++] = level + polyCntX; buffer->indices[i++] = level + polyCntX - 1 + polyCntXpitch; buffer->indices[i++] = level + polyCntX + polyCntXpitch; level += polyCntXpitch; } const u32 polyCntSq = polyCntXpitch*polyCntY; const u32 polyCntSq1 = polyCntSq+1; const u32 polyCntSqM1 = (polyCntY-1)*polyCntXpitch; for(p2=0;p2<polyCntX-1;p2++) { buffer->indices[i++] = polyCntSq; buffer->indices[i++] = p2; buffer->indices[i++] = p2+1; buffer->indices[i++] = polyCntSq1; buffer->indices[i++] = polyCntSqM1+p2; buffer->indices[i++] = polyCntSqM1+p2+1; } buffer->indices[i++] = polyCntSq; buffer->indices[i++] = polyCntX-1; buffer->indices[i++] = polyCntX; buffer->indices[i++] = polyCntSq1; buffer->indices[i++] = polyCntSqM1; buffer->indices[i++] = polyCntSqM1+polyCntX-1; f32 axz; f32 ay = 0; const f32 angelX = 2*M_PI/polyCntX; const f32 angelY = M_PI/polyCntY; i = 0; for(y=0;y<polyCntY;y++) { axz = 0; ay += angelY; const f32 sinay = sinf(ay); for(x=0;x<polyCntX;x++) { const Vector3 pos(static_cast<f32>(radius*cosf(axz)*sinay), static_cast<f32>(radius*cosf(ay)), static_cast<f32>(radius*sinf(axz)*sinay)); Vector3 normal = normalize(pos); f32 tu = 0.5F; if(y==0) { if(normal.getY()!=-1.0F && normal.getY()!=1.0F) tu = static_cast<f32>(acosf(clamp(normal.getX()/sinay,-1.0f,1.0f))*0.5F*RECIPROCAL_PI); if(normal.getZ()<0.0F) tu = 1-tu; } else tu = buffer->vertices[i - polyCntXpitch].u; buffer->vertices[i] = S3DVertex(pos.getX(),pos.getY(),pos.getZ(),normal.getX(),normal.getY(),normal.getZ(),tu,static_cast<f32>(ay*RECIPROCAL_PI)); axz += angelX; i++; } buffer->vertices[i] = S3DVertex(buffer->vertices[i-polyCntX]); buffer->vertices[i].u = 1.0F; i++; } buffer->vertices[i++] = S3DVertex(0.0F,radius,0.0F,0.0F,1.0F,0.0F,0.5F,0.0F); buffer->vertices[i] = S3DVertex(0.0F,-radius,0.0F,0.0F,-1.0F,0.0F,0.5F,1.0F); return buffer; }
static SMeshBuffer* createDonut(f32 outerRadius,f32 innerRadius,u32 polyCntX,u32 polyCntY) { u32 i,x,y,level; SMeshBuffer *buffer = new SMeshBuffer(); if(polyCntX<2) polyCntX = 2; if(polyCntY<2) polyCntY = 2; while(polyCntX*polyCntY>32767) { polyCntX /= 2; polyCntY /= 2; } f32 ay = 0; const f32 angleX = 2*M_PI/polyCntX; const f32 angleY = 2*M_PI/polyCntY; const u32 polyCntXpitch = polyCntX +1; const u32 polyCntYpitch = polyCntY + 1; buffer->cnt_vertices = polyCntYpitch*polyCntXpitch; buffer->vertices = (S3DVertex*)rsxMemalign(128,buffer->cnt_vertices*sizeof(S3DVertex)); buffer->cnt_indices = polyCntY*polyCntX*6; buffer->indices = (u16*)rsxMemalign(128,buffer->cnt_indices*sizeof(u16)); i = 0; for(y=0;y<=polyCntY;y++) { f32 axz = 0; const f32 sinay = sinf(ay); const f32 cosay = cosf(ay); const f32 tu = (f32)y/(f32)polyCntY; for(x=0;x<=polyCntX;x++) { const Vector3 pos(static_cast<f32>((outerRadius - (innerRadius*cosf(axz)))*cosay), static_cast<f32>((outerRadius - (innerRadius*cosf(axz)))*sinay), static_cast<f32>(innerRadius*sinf(axz))); const Vector3 nrm(static_cast<f32>(-cosf(axz)*cosay), static_cast<f32>(-cosf(axz)*sinay), static_cast<f32>(sinf(axz))); buffer->vertices[i] = S3DVertex(pos.getX(),pos.getY(),pos.getZ(),nrm.getX(),nrm.getY(),nrm.getZ(),tu,(f32)x/(f32)polyCntX); axz += angleX; i++; } ay += angleY; } i = 0; level = 0; for(y=0;y<polyCntY;y++) { for(x=0;x<polyCntX - 1;x++) { const u32 curr = level + x; buffer->indices[i++] = curr; buffer->indices[i++] = curr + polyCntXpitch; buffer->indices[i++] = curr + 1 + polyCntXpitch; buffer->indices[i++] = curr; buffer->indices[i++] = curr + 1 + polyCntXpitch; buffer->indices[i++] = curr + 1; } buffer->indices[i++] = level + polyCntX; buffer->indices[i++] = level + polyCntX - 1; buffer->indices[i++] = level + polyCntX - 1 + polyCntXpitch; buffer->indices[i++] = level + polyCntX; buffer->indices[i++] = level + polyCntX - 1 + polyCntXpitch; buffer->indices[i++] = level + polyCntX + polyCntXpitch; level += polyCntXpitch; } return buffer; }
inline void SetS3DVertex(S3DVertex* v, f32 x1, f32 y1, f32 x2, f32 y2, f32 z, f32 nz, f32 tu1, f32 tv1, f32 tu2, f32 tv2) { v[0] = S3DVertex(x1, y1, z, 0, 0, nz, SColor(255, 255, 255, 255), tu1, tv1); v[1] = S3DVertex(x2, y1, z, 0, 0, nz, SColor(255, 255, 255, 255), tu2, tv1); v[2] = S3DVertex(x1, y2, z, 0, 0, nz, SColor(255, 255, 255, 255), tu1, tv2); v[3] = S3DVertex(x2, y2, z, 0, 0, nz, SColor(255, 255, 255, 255), tu2, tv2); }
// SuperTuxKart - a fun racing game with go-kart // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 3 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "graphics/screenquad.hpp" // Just the static parts to our screenquad const u16 ScreenQuad::indices[4] = {0, 1, 2, 3}; static const SColor white(255, 255, 255, 255); const S3DVertex ScreenQuad::vertices[4] = { S3DVertex(-1, 1, 0, 0, 1, 0, white, 0, 1), S3DVertex(1, 1, 0, 0, 1, 0, white, 1, 1), S3DVertex(-1, -1, 0, 0, 1, 0, white, 0, 0), S3DVertex(1, -1, 0, 0, 1, 0, white, 1, 0), };
IMeshSceneNode* CustomSceneNodeManager::CreateCylinderSceneNode(scene::ISceneManager* sceneManager, s32 id, SColor& color, unsigned int resolution, float radius, float height) { /*if (!cylinderMesh) {*/ if (resolution >= 4) { SMesh* newCylinderMesh = new SMesh(); SMeshBuffer* buf = new SMeshBuffer(); newCylinderMesh->addMeshBuffer(buf); buf->MappingHint_Vertex = EHM_STATIC; buf->MappingHint_Index = EHM_STATIC; buf->drop(); int noWarningSignedResolution = resolution; float currentTheta = 0.0f; float skipAmount = 2.0f*PI / (float)resolution; float halfHeight = height / 2.0f; S3DVertex temp1 = S3DVertex(Vector3(0.0f, halfHeight, 0.0f), Vector3_Zero, color, vector2d<f32>(0.0f, 0.0f)); S3DVertex temp2 = S3DVertex(Vector3(0.0f, -halfHeight, 0.0f), Vector3_Zero, color, vector2d<f32>(0.0f, 1.0f)); for(int i = 0; i < noWarningSignedResolution; i++) { float x = cosf(currentTheta) * radius; float z = sinf(currentTheta) * radius; temp1.Pos.X = x; temp1.Pos.Z = z; temp1.TCoords.X = currentTheta / 2.0f*PI; temp2.Pos.X = x; temp2.Pos.Z = z; temp2.TCoords.X = currentTheta / 2.0f*PI; buf->Vertices.push_back(temp1); buf->Vertices.push_back(temp2); currentTheta += skipAmount; } temp1.Pos.X = 0.0f; temp1.Pos.Z = 0.0f; temp1.TCoords.X = 0.0f; temp2.Pos.X = 0.0f; temp2.Pos.Z = 0.0f; temp1.TCoords.X = 0.0f; buf->Vertices.push_back(temp1); buf->Vertices.push_back(temp2); //Get indices for(int i = 0; i < noWarningSignedResolution - 1; i++) { buf->Indices.push_back(i*2); buf->Indices.push_back(i*2+2); buf->Indices.push_back(i*2+1); buf->Indices.push_back(i*2+1); buf->Indices.push_back(i*2+2); buf->Indices.push_back(i*2+3); buf->Indices.push_back(i*2); buf->Indices.push_back(buf->Vertices.size()-2); buf->Indices.push_back(i*2+2); buf->Indices.push_back(i*2+1); buf->Indices.push_back(i*2+3); buf->Indices.push_back(buf->Vertices.size()-1); } buf->Indices.push_back(buf->Vertices.size()-4); buf->Indices.push_back(0); buf->Indices.push_back(buf->Vertices.size()-3); buf->Indices.push_back(buf->Vertices.size()-3); buf->Indices.push_back(0); buf->Indices.push_back(1); buf->Indices.push_back(buf->Vertices.size()-4); buf->Indices.push_back(buf->Vertices.size()-2); buf->Indices.push_back(0); buf->Indices.push_back(buf->Vertices.size()-3); buf->Indices.push_back(1); buf->Indices.push_back(buf->Vertices.size()-1); //Calculate normals CalculateNormals(buf->Vertices, buf->Indices); buf->recalculateBoundingBox(); newCylinderMesh->recalculateBoundingBox(); IMeshSceneNode* node = sceneManager->addMeshSceneNode(newCylinderMesh); newCylinderMesh->drop(); return node; } /* return NULL; } else { IMeshSceneNode* node = sceneManager->addMeshSceneNode(cylinderMesh); node->setScale(Vector3(radius, height, radius)); return node; }*/ return NULL; }
IMeshSceneNode* CustomSceneNodeManager::CreateCapsuleSceneNode(scene::ISceneManager* sceneManager, s32 id, SColor& color, unsigned int resolution, float radius, float heightFromSphereCenters) { if (resolution >= 4) { SMesh* newCapsuleMesh = new SMesh(); SMeshBuffer* buf = new SMeshBuffer(); newCapsuleMesh->addMeshBuffer(buf); buf->MappingHint_Vertex = EHM_STATIC; buf->MappingHint_Index = EHM_STATIC; buf->drop(); int noWarningSignedResolution = resolution; float thetaSkipAmount = 2.0f*PI / (float)resolution; float halfHeight = heightFromSphereCenters / 2.0f; float phiSkipAmount = PI*0.5f / (float)resolution; S3DVertex temp1 = S3DVertex(Vector3(0.0f, halfHeight, 0.0f), Vector3_Zero, color, vector2d<f32>(0.0f, 0.0f)); S3DVertex temp2 = S3DVertex(Vector3(0.0f, -halfHeight, 0.0f), Vector3_Zero, color, vector2d<f32>(0.0f, 1.0f)); float currentTheta = 0.0f; float currentPhi = phiSkipAmount; temp1.Pos.Y = halfHeight + radius; buf->Vertices.push_back(temp1); //Semi-sphere Tips for(unsigned int i = 1; i < resolution; i++) { for(unsigned int j = 0; j < resolution; j++) { float x = sinf(currentPhi) * cosf(currentTheta) * radius; float y = cosf(currentPhi) * radius; float z = sinf(currentPhi) * sinf(currentTheta) * radius; temp1.Pos.X = x; temp1.Pos.Y = y + halfHeight; temp1.Pos.Z = z; temp1.TCoords.X = currentTheta / 2.0f*PI; temp1.TCoords.Y = currentPhi / PI; buf->Vertices.push_back(temp1); currentTheta += thetaSkipAmount; } currentTheta = 0.0f; currentPhi += phiSkipAmount; } currentTheta = 0.0f; currentPhi = PI/2.0f; //Semi-sphere Tips for(unsigned int i = 1; i < resolution; i++) { for(unsigned int j = 0; j < resolution; j++) { float x = sinf(currentPhi) * cosf(currentTheta) * radius; float y = cosf(currentPhi) * radius; float z = sinf(currentPhi) * sinf(currentTheta) * radius; temp1.Pos.X = x; temp1.Pos.Y = y - halfHeight; temp1.Pos.Z = z; temp1.TCoords.X = currentTheta / 2.0f*PI; temp1.TCoords.Y = currentPhi / PI; buf->Vertices.push_back(temp1); currentTheta += thetaSkipAmount; } currentTheta = 0.0f; currentPhi += phiSkipAmount; } temp1.Pos.X = 0.0f; temp1.Pos.Y = -(halfHeight + radius); temp1.Pos.Z = 0.0f; buf->Vertices.push_back(temp1); //Top vertex indices for(unsigned int i = 1; i <= resolution; i++) { if (i == resolution) { buf->Indices.push_back(i); buf->Indices.push_back(0); buf->Indices.push_back(1); } else { buf->Indices.push_back(i); buf->Indices.push_back(0); buf->Indices.push_back(i + 1); } } //Get indices int i = 1 + resolution; while(i < buf->Vertices.size() - 1) { for(unsigned int j = 1; j < resolution; j++) { buf->Indices.push_back(i); buf->Indices.push_back(i - noWarningSignedResolution); buf->Indices.push_back(i - noWarningSignedResolution + 1); buf->Indices.push_back(i); buf->Indices.push_back(i - noWarningSignedResolution + 1); buf->Indices.push_back(i + 1); i++; } buf->Indices.push_back(i); buf->Indices.push_back(i - noWarningSignedResolution); buf->Indices.push_back(i - noWarningSignedResolution + 1 - resolution); buf->Indices.push_back(i); buf->Indices.push_back(i - noWarningSignedResolution + 1 - resolution); buf->Indices.push_back(i + 1 - resolution); i++; } //Bottom vertex indices for(int i = resolution; i >= 1 ; i--) { if (i == 1) { /*buf->Indices.push_back(i); buf->Indices.push_back(0); buf->Indices.push_back(1);*/ buf->Indices.push_back(buf->Vertices.size() -1); buf->Indices.push_back(buf->Vertices.size() -1 - i); buf->Indices.push_back(buf->Vertices.size() - 1 - resolution); } else { buf->Indices.push_back(buf->Vertices.size() -1); buf->Indices.push_back(buf->Vertices.size() -1 - i); buf->Indices.push_back(buf->Vertices.size() - i); } } //Calculate normals CalculateNormals(buf->Vertices, buf->Indices); buf->recalculateBoundingBox(); newCapsuleMesh->recalculateBoundingBox(); IMeshSceneNode* node = sceneManager->addMeshSceneNode(newCapsuleMesh); newCapsuleMesh->drop(); return node; } return NULL; }
IMeshSceneNode* CustomSceneNodeManager::CreateConeSceneNode(scene::ISceneManager* sceneManager, s32 id, SColor& color, unsigned int resolution, float radius, float height) { if (resolution >= 4) { /*IMesh* newConeMesh = sceneManager->getGeometryCreator()->createConeMesh(radius, height, resolution, color, color); IMeshSceneNode* node = sceneManager->addMeshSceneNode(newConeMesh); sceneManager->getMeshCache()->addMesh(irr::io::path("ConeMesh"), (irr::scene::IAnimatedMesh*)newConeMesh); newConeMesh->drop();*/ SMesh* newConeMesh = new SMesh(); SMeshBuffer* buf = new SMeshBuffer(); newConeMesh->addMeshBuffer(buf); buf->MappingHint_Vertex = EHM_STATIC; buf->MappingHint_Index = EHM_STATIC; buf->drop(); int noWarningSignedResolution = resolution; float currentTheta = 0.0f; float skipAmount = 2.0f*PI / (float)resolution; float halfHeight = height / 2.0f; S3DVertex temp1 = S3DVertex(Vector3(0.0f, halfHeight, 0.0f), Vector3_Zero, color, vector2d<f32>(0.0f, 0.0f)); S3DVertex temp2 = S3DVertex(Vector3(0.0f, -halfHeight, 0.0f), Vector3_Zero, color, vector2d<f32>(0.0f, 1.0f)); for(int i = 0; i < noWarningSignedResolution; i++) { float x = cosf(currentTheta) * radius; float z = sinf(currentTheta) * radius; temp2.Pos.X = x; temp2.Pos.Z = z; temp2.TCoords.X = currentTheta / 2.0f*PI; buf->Vertices.push_back(temp2); currentTheta += skipAmount; } buf->Vertices.push_back(temp1); //Get side indices for(int i = 0; i < noWarningSignedResolution - 1; i++) { buf->Indices.push_back(i); buf->Indices.push_back(buf->Vertices.size()-1); buf->Indices.push_back(i+1); } buf->Indices.push_back(buf->Vertices.size()-2); buf->Indices.push_back(buf->Vertices.size()-1); buf->Indices.push_back(0); temp2.Pos.X = 0.0f; temp2.Pos.Z = 0.0f; buf->Vertices.push_back(temp2); //Get bottom indices for(int i = 0; i < noWarningSignedResolution - 1; i++) { buf->Indices.push_back(i); buf->Indices.push_back(i+1); buf->Indices.push_back(buf->Vertices.size()-1); } buf->Indices.push_back(buf->Vertices.size()-1); buf->Indices.push_back(buf->Vertices.size()-3); buf->Indices.push_back(0); //Calculate normals CalculateNormals(buf->Vertices, buf->Indices); buf->recalculateBoundingBox(); newConeMesh->recalculateBoundingBox(); IMeshSceneNode* node = sceneManager->addMeshSceneNode(newConeMesh); newConeMesh->drop(); return node; } return NULL; }
void GrassNode::Load(stringc filename,s32 frmWidth,s32 frmHeight) { IVideoDriver* driver = SceneManager->getVideoDriver(); //dimension2d<u32> Screensize = driver->getScreenSize(); fx = (float)frmWidth;// /(float)Screensize.Width; fy = (float)frmHeight;// /(float)Screensize.Height; Vertices[0] = S3DVertex(-fx,-fy,0, 0,0,0,SColor(255,255,255,255),0,1); Vertices[1] = S3DVertex( fx,-fy,0, 0,0,0,SColor(255,255,255,255),1,1); Vertices[2] = S3DVertex( fx, fy,0, 0,0,0,SColor(255,255,255,255),1,0); Vertices[3] = S3DVertex(-fx, fy,0, 0,0,0,SColor(255,255,255,255),0,0); Box.reset(Vertices[0].Pos); for (s32 i=1; i<4; ++i) Box.addInternalPoint(Vertices[i].Pos); Texture = driver->getTexture(filename); //driver->makeColorKeyTexture(Texture,position2d<s32>(0,0)); Material.setTexture(0,Texture); Material.TextureLayer[0].BilinearFilter = false; Material.MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL_REF; dimension2d<u32> size = Texture->getOriginalSize(); fWidth = (float)frmWidth/(float)size.Width; fHeight = (float)frmHeight/(float)size.Height; stepww = size.Width / frmWidth; stephh = size.Height / frmHeight; Vertices[0].TCoords.X = 0; Vertices[0].TCoords.Y = fHeight; Vertices[1].TCoords.X = fWidth; Vertices[1].TCoords.Y = fHeight; Vertices[2].TCoords.X = fWidth; Vertices[2].TCoords.Y = 0; Vertices[3].TCoords.X = 0; Vertices[3].TCoords.Y = 0; // Place Holder < ---------------------------------------- < - < - < - > amount = 4; for (unsigned int i = 0; i < amount; i++) { frames[i].preLoopFrame = 0; frames[i].startFrame = 0; frames[i].endFrame = 0; frames[i].time = 60; } // Box2d body = 0; b2BodyDef myBody; myBody.type = b2_staticBody; myBody.position.Set( 0, 0 ); myBody.angle = 0; myBody.fixedRotation = true; body = physics->world->CreateBody(&myBody); for (int j = -57; j < 13; j++) // TEMP for (int k = 0; k < 1; k++) createParticle((float)frmWidth, (float)frmHeight, b2Vec2(j,k + 0.25)); for (int j = 49; j < 100; j++) // TEMP for (int k = 0; k < 1; k++) createParticle((float)frmWidth, (float)frmHeight, b2Vec2(j,k + 0.25)); SetSpeed(80); }