Monocyte *Hero::shootMonocyte() { Cursor *cursor; Vect4 cursorPosition; list<list<PhysicalComponent *>*> neighborhood; cursor = engine->getCursor(); cursorPosition = cursor->getPhysicalComponent()->getPosition(); neighborhood = engine->getParentEngine()->getPhysicalEngine()->getGrid()->getNeighborhood(cursorPosition[0], cursorPosition[1], 30); PhysicalComponent *nearest = NULL; PhysicalComponent *physicalComponent = NULL; GameObject *gameObject = NULL; float minDist = 999999999, currentDist = 0; ObjectType currentType; for (list<list<PhysicalComponent *>*>::iterator j = neighborhood.begin(); j != neighborhood.end();) { for (list<PhysicalComponent *>::iterator i = (*j)->begin(); i != (*j)->end();) { gameObject = (*i)->getGameObject(); physicalComponent = (*i); if (gameObject != NULL) { currentType = gameObject->getObjectType(); switch (currentType) { case cancerTypeDeclared:; case virusType:; case bacteriaType: case bacteriaWasteType: currentDist = Vect4(physicalComponent->getPosition() - cursorPosition).norme(); if (currentDist < minDist) { nearest = physicalComponent; minDist = currentDist; } break; default:break; } } ++i; } ++j; } if (nearest != NULL) { Monocyte *monocyte = new Monocyte(engine,nearest->getGameObject()); return monocyte; } return NULL; }
void Diamond::initialize( InstanceIDPool &symbolIdPool ) { if( line.valid() ) { removeSymbol( line.get() ); line = NULL; } int symbolID = symbolIdPool.getAvailableID(); if( symbolID > 0xffff ) { std::cerr << "In Diamond::initialize - no more available symbol IDs\n"; symbolIdPool.relenquishID( symbolID ); return; } line = new SymbolLine; line->addImplementation( new SerializableSymbolLine( line.get(), outgoingMessage ) ); line->setID( symbolID ); line->setState( Symbol::Visible ); line->setSurfaceID( SURFACE_ID ); line->setColor( Vect4( 0.5, 0.7, 1.0, 1.0 ) ); line->setFlashDutyCyclePercentage( 100 ); line->setPosition( randFloat( SURFACE_MIN_U, SURFACE_MAX_U ), randFloat( SURFACE_MIN_V, SURFACE_MAX_V ) ); // line->setRotation( randFloat( 0.0, 360.0 ) ); line->setRotation( 0.0 ); line->setPrimitiveType( SymbolLine::LineLoop ); /* line->addVertex( -0.07, 0.0 ); line->addVertex( 0.0, -0.04 ); line->addVertex( 0.07, 0.0 ); line->addVertex( 0.0, 0.04 );*/ line->addVertex( -0.05, 0.0 ); line->addVertex( 0.0, -0.05 ); line->addVertex( 0.05, 0.0 ); line->addVertex( 0.0, 0.05 ); addSymbol( line.get() ); velocity.Set( randFloat( -1.0, 1.0 ), randFloat( -1.0, 1.0 ) ); rotationalVelocity = randFloat( -90.0, 90.0 ); }
void LowerLeftCluster::initialize( InstanceIDPool &symbolIdPool ) { text = new SymbolText(); text->setID( symbolIdPool.getAvailableID() ); // fixme - error checking addSymbol( text.get() ); text->addImplementation( new SerializableSymbolText( text.get(), outgoingMessage ) ); text->setState( Symbol::Visible ); text->setSurfaceID( SURFACE_ID ); text->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); text->setFlashDutyCyclePercentage( 100 ); text->setPosition( -7.5, 0.5 ); text->setRotation( 0.0 ); text->setTextAlignment( SymbolText::TopLeft ); text->setTextOrientation( SymbolText::LeftToRight ); text->setFontID( 0 ); // fixme - fonts text->setFontSize( 1.35 ); text->setText( "a XX.X\nM XX.XX\nG XX.X\n XX.X\n\nXX:XX:XXZ" ); textChanged( hudState.get() ); }
const Vect4 Vect4::operator-(const Vect4& other) const { return Vect4(x - other.x, y - other.y, z - other.z, w - other.w); }
void MeshEntity::OnUpdatePosition() { traceInFast(MeshEntity::OnUpdatePosition); Super::OnUpdatePosition(); for(int i=0; i<MeshLights.Num(); i++) MeshLights[i].light->RemoveEntity(this, MeshLights[i].side); MeshLights.Clear(); List<LevelObject*> objects; level->GetObjects(bounds.GetTransformedBounds(transform), objects); for(int i=0; i<objects.Num(); i++) { LevelObject *levelObj = objects[i]; if(levelObj->type == ObjectType_Entity) { if(!levelObj->ent->IsOf(GetClass(Light))) continue; Light *light = (Light*)levelObj->ent; light->ProcessEntity(this); } } if(bStaticGeometry) return; Vect position = GetWorldPos()+adjustPos; Quat rotation = GetWorldRot()*adjustRot; Matrix transform; transform.SetIdentity(); transform.Rotate(rotation.GetInv()); transform.Translate(-position); SH.Clear(); level->GetSHIndirectLightSamples(GetWorldPos(), indirectLightDist, transform, SH); if(shadowDecal) { Vect shadowRot = -shadowDecal->shadowRot.GetDirectionVector(); Vect color(0.0f); if(SH.Num()) { color += Vect(SH[0]) * shadowRot.x; color += Vect(SH[1]) * shadowRot.y; color += Vect(SH[2]) * shadowRot.z; color += Vect(SH[3]) * fabsf(shadowRot.x); color += Vect(SH[4]) * fabsf(shadowRot.y); color += Vect(SH[5]) * fabsf(shadowRot.z); } else color = 0.3f; shadowDecal->decalColor = Vect4(color); shadowDecal->decalColor.w = (color.x+color.y+color.z)/3.0f; shadowDecal->decalColor.w = MIN(shadowDecal->decalColor.w*0.5f, 1.0f); shadowDecal->decalColor.w = 1.0f-(shadowDecal->decalColor.w*0.8f); } traceOutFast; }
const Vect4 Vect4::operator+(const Vect4& other) const { return Vect4(x + other.x, y + other.y, z + other.z, w + other.w); }
void VelocityVector::initialize( InstanceIDPool &symbolIdPool ) { waterlineReference = new SymbolLine(); waterlineReference->setID( symbolIdPool.getAvailableID() ); // fixme - error checking addSymbol( waterlineReference.get() ); waterlineReference->addImplementation( new SerializableSymbolLine( waterlineReference.get(), outgoingMessage ) ); waterlineReference->setState( Symbol::Visible ); waterlineReference->setSurfaceID( SURFACE_ID ); waterlineReference->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); waterlineReference->setFlashDutyCyclePercentage( 100 ); waterlineReference->setPosition( 0.0, waterlinePosition ); waterlineReference->setRotation( 0.0 ); // waterlineReference has no geometry pip = new SymbolCircle(); pip->setID( symbolIdPool.getAvailableID() ); // fixme - error checking pip->setParent( true, waterlineReference->getID(), waterlineReference.get() ); waterlineReference->addSymbol( pip.get() ); pip->addImplementation( new SerializableSymbolCircle( pip.get(), outgoingMessage ) ); pip->setState( Symbol::Visible ); pip->setSurfaceID( SURFACE_ID ); pip->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); pip->setFlashDutyCyclePercentage( 100 ); pip->setPosition( 0.0, 0.0 ); pip->setRotation( 0.0 ); pip->setDrawingStyle( SymbolCircle::Line ); SymbolCircle::Circle circle; circle.centerPosition.Set( 0., 0. ); circle.radius = pipRadius; circle.innerRadius = 0.; // unused circle.startAngle = 0.; circle.endAngle = 0.; pip->addCircle( circle ); SymbolLine *line = new SymbolLine(); line->setID( symbolIdPool.getAvailableID() ); // fixme - error checking line->setParent( true, pip->getID(), pip.get() ); pip->addSymbol( line ); line->addImplementation( new SerializableSymbolLine( line, outgoingMessage ) ); line->setState( Symbol::Visible ); line->setSurfaceID( SURFACE_ID ); line->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); line->setFlashDutyCyclePercentage( 100 ); line->setPosition( 0., 0. ); line->setRotation( 0.0 ); line->setPrimitiveType( SymbolLine::Lines ); line->addVertex( 0.0, pipRadius ); line->addVertex( 0.0, pipRadius + 0.6 ); line->addVertex( -pipRadius, 0. ); line->addVertex( -pipRadius - 0.7, 0. ); line->addVertex( pipRadius, 0. ); line->addVertex( pipRadius + 0.7, 0. ); velocityVectorPositionChanged( hudState.get() ); }
void Camera::renderMesh(Mesh *m, Surface *s) { Graphics g (s); Vect4 *transVerts = new Vect4[m->verts.size()]; //Temporary storage for transformed vertices Mat4 temp = Mat4::IdentityMat(); double sf = 1; Vect4 tempLighting = Vect4::unit(Vect4(1, 1, 2)); int *lightVals = new int[m->faces.size()]; temp = m->forwardMat(); //Temporary shift!! temp = Mat4::mult(Mat4::TranslateMat(Vect4(0,0,-15)), temp); temp = Mat4::mult(Mat4::ProjectPersp(), temp); //Transform points for(int i = 0; (size_t)i < m->verts.size(); i++) { transVerts[i] = temp.mult(m->verts[i]); } //Grab light values for(int i = 0; (size_t)i < m->faces.size(); i++) { Vect4 v1 = transVerts[m->faces[i].v1]; Vect4 v2 = transVerts[m->faces[i].v2]; Vect4 v3 = transVerts[m->faces[i].v3]; if(isBackface(v1, v2, v3)) ;//continue;//g.setColor(255, 0, 0);//continue; double light = Vect4::dot(tempLighting, Vect4::unit(Vect4::cross(v2 - v1, v3 - v1))); if(light > 0) { lightVals[i] = light * 255; } else { lightVals[i] = 0; } } //Normalize w (only for x and y) for(int i = 0; (size_t)i < m->verts.size(); i++) { transVerts[i].coord[0] /= transVerts[i].coord[3]; transVerts[i].coord[1] /= transVerts[i].coord[3]; if(transVerts[i].coord[3] < 0.01 && transVerts[i].coord[3] > -0.01) { //std::cerr << i << " " << transVerts[i].coord[3] << " woop\n"; } } //Figure out mapping of points to screen //mapsize is how wide half the screen should be //In world units double mapsize = tan(d2r(fov / 2)); double pixScale = s->width / (2 * mapsize); //How wide is a unit in pixels double offX = s->width / 2; double offY = s->height / 2; //Transform to screen coords for(int i = 0; (size_t)i < m->verts.size(); i++) { transVerts[i].coord[0] = transVerts[i].coord[0] * pixScale + offX; transVerts[i].coord[1] = transVerts[i].coord[1] * pixScale + offY; } //Draw Triangles for(int i = 0; (size_t)i < m->faces.size(); i++) { Vect4 v1 = transVerts[m->faces[i].v1]; Vect4 v2 = transVerts[m->faces[i].v2]; Vect4 v3 = transVerts[m->faces[i].v3]; if(isBackface(v1, v2, v3)) continue;//g.setColor(255, 0, 0);//continue; double l = lightVals[i]; g.setColor(l,l,l); g.fillTri( PointZ ((int)v1[0], (int)v1[1], v1[2]), PointZ ((int)v2[0], (int)v2[1], v2[2]), PointZ ((int)v3[0], (int)v3[1], v3[2])); } //Draw wireframe faces with transformed vertices /* g.setColor(0,0,0); for(int i = 0; (size_t)i < m->faces.size(); i++) { Vect4 v1 = transVerts[m->faces[i].v1]; Vect4 v2 = transVerts[m->faces[i].v2]; Vect4 v3 = transVerts[m->faces[i].v3]; g.drawLineZ((int)v1[0], (int)v1[1], v1[2], (int)v2[0], (int)v2[1], v2[2]); g.drawLineZ((int)v2[0], (int)v2[1], v2[2], (int)v3[0], (int)v3[1], v3[2]); g.drawLineZ((int)v3[0], (int)v3[1], v3[2], (int)v1[0], (int)v1[1], v1[2]); } */ delete transVerts; delete lightVals; }
Vect4 Vect4::inverse() const { return Vect4 (-1 * coord[0], -1 * coord[1], -1 * coord[2]); }
void My3DEngine::Setup(HWND hWnd) { glPolygonMode(GL_FRONT_AND_BACK, GL_SMOOTH); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_CULL_FACE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, modelAmbient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat1Diffuse); glMaterialfv(GL_FRONT, GL_AMBIENT, mat1Ambient); glMaterialfv(GL_FRONT, GL_SPECULAR, mat1Specular); glMaterialf(GL_FRONT, GL_SHININESS, 0.5); const char *test = "3DS/Island 001/Island_001.obj"; load(&test,1); MyLight * light = new MyLight(Matrx44( Vect4(0.2,0.2,0.2, 1), Vect4(0.5, 0.5, 0.5, 1), Vect4(0.8, 0.8, 0.8, 1), Vect4(10, 10, 10, 0))); int lightId = renderer->addLight(light); logs.open("log.txt", std::ios::trunc); /* for (int o = 0; o < scene->u32ObjectsCount; o++) { if (scene->pObjects[o].u32Material != UINT_MAX){ IMAGE_DATA *image = NULL; image = scene->pMaterials[scene->pObjects[o].u32Material].pDiffuse; if (image != NULL) { image->pUserData = new GLuint(); glGenTextures(1, (GLuint *)image->pUserData); glBindTexture(GL_TEXTURE_2D, *(GLuint *)(image->pUserData)); logs << "ID créés : " << std::endl; logs << *(GLuint *)image->pUserData << std::endl; unsigned int b = 24; GLenum format = GL_RGB; if (scene->pMaterials[scene->pObjects[o].u32Material].pDiffuse->PixelFormat != 0) { b = 32; format = GL_RGBA; } glTexImage2D( GL_TEXTURE_2D, 0, format, image->u32Width, image->u32Height, 0, format, GL_UNSIGNED_BYTE, image->pu8Pixels ); glTexEnvi(GL_TEXTURE, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } } } */ logs << "***********************************************************************************************************************************" << std::endl; /* delete[]vertice_coord; delete[]faces; delete[]normals;*/ //Shaders init }
const Vect4 Vect4::operator+ (const Vect4 &rhs) { return Vect4( coord[0] + rhs.coord[0], coord[1] + rhs.coord[1], coord[2] + rhs.coord[2]); }
void AltitudeBox::initialize( InstanceIDPool &symbolIdPool ) { box = new SymbolLine(); box->setID( symbolIdPool.getAvailableID() ); // fixme - error checking addSymbol( box.get() ); box->addImplementation( new SerializableSymbolLine( box.get(), outgoingMessage ) ); box->setState( Symbol::Visible ); box->setSurfaceID( SURFACE_ID ); box->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); box->setFlashDutyCyclePercentage( 100 ); box->setPosition( 7.5, 4.0 ); box->setRotation( 0.0 ); box->setPrimitiveType( SymbolLine::LineLoop ); box->addVertex( -2.3, -0.4 ); box->addVertex( 0.0, -0.4 ); box->addVertex( 0.0, 0.4 ); box->addVertex( -2.3, 0.4 ); textThousands = new SymbolText(); textThousands->setID( symbolIdPool.getAvailableID() ); // fixme - error checking textThousands->setParent( true, box->getID(), box.get() ); box->addSymbol( textThousands.get() ); textThousands->addImplementation( new SerializableSymbolText( textThousands.get(), outgoingMessage ) ); textThousands->setState( Symbol::Visible ); textThousands->setSurfaceID( SURFACE_ID ); textThousands->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); textThousands->setFlashDutyCyclePercentage( 100 ); textThousands->setPosition( -1.2, 0.0 ); textThousands->setRotation( 0.0 ); textThousands->setTextAlignment( SymbolText::CenterRight ); textThousands->setTextOrientation( SymbolText::LeftToRight ); textThousands->setFontID( 0 ); // fixme - fonts textThousands->setFontSize( 1.5 ); textThousands->setText( "XX" ); textRemainder = new SymbolText(); textRemainder->setID( symbolIdPool.getAvailableID() ); // fixme - error checking textRemainder->setParent( true, box->getID(), box.get() ); box->addSymbol( textRemainder.get() ); textRemainder->addImplementation( new SerializableSymbolText( textRemainder.get(), outgoingMessage ) ); textRemainder->setState( Symbol::Visible ); textRemainder->setSurfaceID( SURFACE_ID ); textRemainder->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); textRemainder->setFlashDutyCyclePercentage( 100 ); textRemainder->setPosition( -0.1, 0.06 ); textRemainder->setRotation( 0.0 ); textRemainder->setTextAlignment( SymbolText::CenterRight ); textRemainder->setTextOrientation( SymbolText::LeftToRight ); textRemainder->setFontID( 0 ); // fixme - fonts textRemainder->setFontSize( 1.35 ); textRemainder->setText( "XXX" ); textDebug = new SymbolText(); textDebug->setID( symbolIdPool.getAvailableID() ); // fixme - error checking addSymbol( textDebug.get() ); textDebug->addImplementation( new SerializableSymbolText( textDebug.get(), outgoingMessage ) ); textDebug->setState( Symbol::Visible ); textDebug->setSurfaceID( SURFACE_ID ); textDebug->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); textDebug->setFlashDutyCyclePercentage( 100 ); textDebug->setPosition( 6.6, 5.0 ); textDebug->setRotation( 0.0 ); textDebug->setTextAlignment( SymbolText::Center ); textDebug->setTextOrientation( SymbolText::LeftToRight ); textDebug->setFontID( 0 ); // fixme - fonts textDebug->setFontSize( 1.5 ); textDebug->setText( "XXXXX" ); }
void Pinwheel::initialize( InstanceIDPool &symbolIdPool ) { if( line.valid() ) { removeSymbol( line.get() ); line = NULL; } int symbolID = symbolIdPool.getAvailableID(); if( symbolID > 0xffff ) { std::cerr << "In Pinwheel::initialize - no more available symbol IDs\n"; symbolIdPool.relenquishID( symbolID ); return; } int childSymbolID = symbolIdPool.getAvailableID(); if( childSymbolID > 0xffff ) { std::cerr << "In Pinwheel::initialize - no more available symbol IDs\n"; symbolIdPool.relenquishID( childSymbolID ); return; } line = new SymbolLine; line->addImplementation( new SerializableSymbolLine( line.get(), outgoingMessage ) ); line->setID( symbolID ); line->setState( Symbol::Visible ); line->setSurfaceID( SURFACE_ID ); line->setColor( Vect4( 0.8, 0.0, 1.0, 1.0 ) ); line->setFlashDutyCyclePercentage( 100 ); line->setPosition( randFloat( SURFACE_MIN_U, SURFACE_MAX_U ), randFloat( SURFACE_MIN_V, SURFACE_MAX_V ) ); line->setRotation( randFloat( 0.0, 360.0 ) ); line->setPrimitiveType( SymbolLine::LineLoop ); line->addVertex( 0.05, -0.05 ); line->addVertex( 0.0, -0.05 ); line->addVertex( 0.0, 0.05 ); line->addVertex( -0.05, 0.05 ); SymbolLine *childLine = new SymbolLine; childLine->addImplementation( new SerializableSymbolLine( childLine, outgoingMessage ) ); childLine->setID( childSymbolID ); childLine->setState( Symbol::Visible ); childLine->setSurfaceID( SURFACE_ID ); childLine->setInheritColor( true ); childLine->setFlashDutyCyclePercentage( 100 ); childLine->setPosition( 0, 0 ); childLine->setRotation( 90 ); childLine->setPrimitiveType( SymbolLine::LineLoop ); childLine->addVertex( 0.05, -0.05 ); childLine->addVertex( 0.0, -0.05 ); childLine->addVertex( 0.0, 0.05 ); childLine->addVertex( -0.05, 0.05 ); childLine->setParent( true, symbolID, line.get() ); line->addSymbol( childLine ); addSymbol( line.get() ); velocity.Set( randFloat( -1.0, 1.0 ), randFloat( -1.0, 1.0 ) ); // clockwise versus counter-clockwise if( randBool() ) { rotationalVelocity *= -1.0f; line->setScale( -1.0f, 1.0f ); } }
const Vect4 Vect4::operator- (const Vect4 &rhs) { return Vect4( coord[0] - rhs.coord[0], coord[1] - rhs.coord[1], coord[2] - rhs.coord[2]); }
void HeadingCluster::initialize( InstanceIDPool &symbolIdPool ) { int topBoxID = getSymbolID( symbolIdPool ); if( topBoxID < 0 ) { std::cerr << "In HeadingCluster::initialize - no more available symbol IDs\n"; return; } int topTextID = getSymbolID( symbolIdPool ); if( topTextID < 0 ) { std::cerr << "In HeadingCluster::initialize - no more available symbol IDs\n"; return; } int debugOutlineID = getSymbolID( symbolIdPool ); if( debugOutlineID < 0 ) { std::cerr << "In HeadingCluster::initialize - no more available symbol IDs\n"; return; } topBox = new SymbolLine(); topBox->setID( topBoxID ); addSymbol( topBox.get() ); topBox->addImplementation( new SerializableSymbolLine( topBox.get(), outgoingMessage ) ); topBox->setState( Symbol::Visible ); topBox->setSurfaceID( SURFACE_ID ); topBox->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); topBox->setFlashDutyCyclePercentage( 100 ); topBox->setPosition( 0.0, 9.0 ); topBox->setRotation( 0.0 ); topBox->setPrimitiveType( SymbolLine::LineLoop ); topBox->addVertex( -0.85, -0.45 ); topBox->addVertex( 0.85, -0.45 ); topBox->addVertex( 0.85, 0.45 ); topBox->addVertex( -0.85, 0.45 ); topText = new SymbolText(); topText->setID( topTextID ); topText->setParent( true, topBox->getID(), topBox.get() ); addSymbol( topText.get() ); topText->addImplementation( new SerializableSymbolText( topText.get(), outgoingMessage ) ); topText->setState( Symbol::Visible ); topText->setSurfaceID( SURFACE_ID ); topText->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); topText->setFlashDutyCyclePercentage( 100 ); topText->setPosition( 0.0, 0.0 ); topText->setRotation( 0.0 ); topText->setTextAlignment( SymbolText::Center ); topText->setTextOrientation( SymbolText::LeftToRight ); topText->setFontID( 0 ); // fixme - fonts topText->setFontSize( 1.5 ); topText->setText( "XXX" ); barLine = new SymbolLine(); barLine->setID( symbolIdPool.getAvailableID() ); // fixme - error checking addSymbol( barLine.get() ); barLine->addImplementation( new SerializableSymbolLine( barLine.get(), outgoingMessage ) ); barLine->setState( Symbol::Visible ); barLine->setSurfaceID( SURFACE_ID ); barLine->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); barLine->setFlashDutyCyclePercentage( 100 ); barLine->setPosition( 0.0, 7.0 ); barLine->setRotation( 0.0 ); barLine->setPrimitiveType( SymbolLine::Lines ); // the bar itself barLine->addVertex( -barWidth / 2., 0. ); barLine->addVertex( barWidth / 2., 0. ); // the caret below the bar barLine->addVertex( 0., 0. ); barLine->addVertex( -0.3, -0.5 ); barLine->addVertex( 0., 0. ); barLine->addVertex( 0.3, -0.5 ); barTicks = new SymbolLine(); barTicks->setID( symbolIdPool.getAvailableID() ); // fixme - error checking barTicks->setParent( true, barLine->getID(), barLine.get() ); barLine->addSymbol( barTicks.get() ); barTicks->addImplementation( new SerializableSymbolLine( barTicks.get(), outgoingMessage ) ); barTicks->setState( Symbol::Visible ); barTicks->setSurfaceID( SURFACE_ID ); barTicks->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); barTicks->setFlashDutyCyclePercentage( 100 ); barTicks->setPosition( 0.0, 0.0 ); barTicks->setRotation( 0.0 ); barTicks->setPrimitiveType( SymbolLine::LineLoop ); //barTicks->addVertex( 0., 0.0 ); //barTicks->addVertex( -0.18, 0.18 ); //barTicks->addVertex( 0.18, 0.18 ); float tickInterval = barWidth / ( ticksRange / degreesPerTick ); int numVertices = 0; SymbolLine *tickChild = NULL; // limited to 30 vertices per line symbol; need to split up ticks into // multiple symbols for( float x = -barWidth / 2.; x < barWidth / 2.; x += tickInterval ) { // note - actually limited to 28 vertices, due to CCL bug if( tickChild == NULL || numVertices >= 26 ) { tickChild = new SymbolLine(); tickChild->setID( symbolIdPool.getAvailableID() ); // fixme - error checking tickChild->setParent( true, barTicks->getID(), barTicks.get() ); barTicks->addSymbol( tickChild ); tickChild->addImplementation( new SerializableSymbolLine( tickChild, outgoingMessage ) ); tickChild->setState( Symbol::Visible ); tickChild->setSurfaceID( SURFACE_ID ); tickChild->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); tickChild->setFlashDutyCyclePercentage( 100 ); tickChild->setPosition( 0.0, 0.0 ); tickChild->setRotation( 0.0 ); tickChild->setPrimitiveType( SymbolLine::Lines ); numVertices = 0; } tickChild->addVertex( x, 0.0 ); numVertices++; tickChild->addVertex( x, 0.18 ); numVertices++; } textTicks = new SymbolText(); textTicks->setID( symbolIdPool.getAvailableID() ); // fixme - error checking textTicks->setParent( true, barLine->getID(), barLine.get() ); barLine->addSymbol( textTicks.get() ); textTicks->addImplementation( new SerializableSymbolText( textTicks.get(), outgoingMessage ) ); textTicks->setState( Symbol::Visible ); textTicks->setSurfaceID( SURFACE_ID ); textTicks->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); textTicks->setFlashDutyCyclePercentage( 100 ); textTicks->setPosition( 0.0, 0.0 ); textTicks->setRotation( 0.0 ); // list of text symbols for numbers above bar ticks tickInterval = barWidth / ( ticksRange / degreesPerTextTick ); for( float x = -barWidth / 2.; x < barWidth / 2.; x += tickInterval ) { SymbolText *text = new SymbolText(); text->setID( symbolIdPool.getAvailableID() ); // fixme - error checking text->setParent( true, textTicks->getID(), textTicks.get() ); textTicks->addSymbol( text ); text->addImplementation( new SerializableSymbolText( text, outgoingMessage ) ); text->setState( Symbol::Visible ); text->setSurfaceID( SURFACE_ID ); text->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); text->setFlashDutyCyclePercentage( 100 ); text->setPosition( x, 0.25 ); text->setRotation( 0.0 ); text->setTextAlignment( SymbolText::BottomCenter ); text->setTextOrientation( SymbolText::LeftToRight ); text->setFontID( 0 ); // fixme - fonts text->setFontSize( 1.2 ); text->setText( "XXX" ); textTicksList.push_back( text ); } waypointTick = new SymbolLine(); waypointTick->setID( symbolIdPool.getAvailableID() ); // fixme - error checking waypointTick->setParent( true, barLine->getID(), barLine.get() ); barLine->addSymbol( waypointTick.get() ); waypointTick->addImplementation( new SerializableSymbolLine( waypointTick.get(), outgoingMessage ) ); waypointTick->setState( Symbol::Visible ); waypointTick->setSurfaceID( SURFACE_ID ); waypointTick->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); waypointTick->setFlashDutyCyclePercentage( 100 ); waypointTick->setPosition( 0.0, 0.0 ); waypointTick->setRotation( 0.0 ); waypointTick->setPrimitiveType( SymbolLine::TriangleFan ); waypointTick->addVertex( -0.1, 0.0 ); waypointTick->addVertex( -0.1, -0.6 ); waypointTick->addVertex( 0.1, -0.6 ); waypointTick->addVertex( 0.1, 0.0 ); debugOutline = new SymbolLine(); debugOutline->setID( debugOutlineID ); addSymbol( debugOutline.get() ); debugOutline->addImplementation( new SerializableSymbolLine( debugOutline.get(), outgoingMessage ) ); debugOutline->setState( Symbol::Visible ); debugOutline->setSurfaceID( SURFACE_ID ); debugOutline->setColor( Vect4( 0.0, 1.0, 0.0, 1.0 ) ); debugOutline->setFlashDutyCyclePercentage( 100 ); debugOutline->setPosition( 0.0, 0.0 ); debugOutline->setRotation( 0.0 ); debugOutline->setPrimitiveType( SymbolLine::LineLoop ); debugOutline->addVertex( SURFACE_MIN_U, SURFACE_MIN_V ); debugOutline->addVertex( SURFACE_MAX_U, SURFACE_MIN_V ); debugOutline->addVertex( SURFACE_MAX_U, SURFACE_MAX_V ); debugOutline->addVertex( SURFACE_MIN_U, SURFACE_MAX_V ); }
//+X x +Z //0 - (1 0) //(0 * 1) - (1 1) //(1 0) - (0 0) Vect4 Vect4::cross(Vect4 l, Vect4 r) { return Vect4( l[1] * r[2] - l[2] * r[1], l[2] * r[0] - l[0] * r[2], l[0] * r[1] - l[1] * r[0]); }
Vect4 Vect4::vLerp(Vect4 a, Vect4 b, double t) { return Vect4( lerp(a[0],b[0], t), lerp(a[1],b[1], t), lerp(a[2],b[2], t)); }
const Vect4 Vect4::operator*(const float scaler) const { return Vect4(x * scaler, y * scaler, z * scaler, w * scaler); }
void render(Scene& scene, Texture& screen, int renderno = 0, int outof = 1) { char titlebuf[200]; if (settings.show_preview) { sprintf(titlebuf, "%s", TITLE); SDL_SetWindowTitle(window, titlebuf); } Vect4 color; bool exitflag = 0; int v; //Return value from threads RenderQueue rq(&scene, &screen); SDL_Thread** threads = new SDL_Thread* [settings.nworkers]; rq.pushRow(0); for (int i = 0; i < settings.nworkers; i++) threads[i] = SDL_CreateThread(&renderThread, NULL, &rq); for (int i = 0; i < settings.nworkers; i++) SDL_WaitThread(threads[i], &v); for (int r = 1; r < screen.height(); r++) { if (settings.show_preview) { SDL_Event event; while (SDL_PollEvent(&event)) if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)) exit(0); else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) exitflag = 1; if (exitflag) break; } rq.pushRow(r); for (int i = 0; i < settings.nworkers; i++) threads[i] = SDL_CreateThread(&renderThread, NULL, &rq); if (settings.show_preview) { drawRow(screen, r - 1); px->redraw(); SDL_RenderPresent(px->getRenderer()); } for (int i = 0; i < settings.nworkers; i++) SDL_WaitThread(threads[i], &v); if (outof > 1) sprintf(titlebuf, "%s [%d / %d, %d of %d]",TITLE, r + 1, screen.height(), renderno, outof); else sprintf(titlebuf, "%s [%d / %d]", TITLE, r + 1, screen.height()); if (settings.show_preview) SDL_SetWindowTitle(window, titlebuf); else { printf("\r%s", titlebuf); fflush(0); } } if (settings.show_preview) { drawRow(screen, screen.height() - 1); px->redraw(); SDL_RenderPresent(px->getRenderer()); } else printf("\n"); if (!settings.aa_enabled) { delete [] threads; return; } Texture dmap = screen.differenceMap(); float d; for (int r = 1; r < screen.height() - 1; r++) { if (settings.show_preview) { SDL_Event event; while (SDL_PollEvent(&event)) if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)) exit(0); else if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN) exitflag = 1; if (exitflag) break; } for (int c = 1; c < screen.width() - 1; c++) { d = dot(dmap.getColor(r, c), Vect4(1, 1, 1, 0)); if (d > settings.aa_threshold) rq.push(r, c); } for (int i = 0; i < settings.nworkers; i++) threads[i] = SDL_CreateThread(&renderThread_AA, NULL, &rq); if (settings.show_preview) { drawRow(screen, r - 1); px->redraw(); SDL_RenderPresent(px->getRenderer()); } for (int i = 0; i < settings.nworkers; i++) SDL_WaitThread(threads[i], &v); if (outof > 1) sprintf(titlebuf, "%s [AA: %d / %d, %d of %d]", TITLE, r + 2, screen.height(), renderno, outof); else sprintf(titlebuf, "%s [AA: %d / %d]",TITLE, r + 2, screen.height()); if (settings.show_preview) SDL_SetWindowTitle(window, titlebuf); else { printf("\r%s", titlebuf); fflush(0); } } delete [] threads; if (settings.show_preview) { drawRow(screen, screen.height() - 2); px->redraw(); SDL_RenderPresent(px->getRenderer()); SDL_SetWindowTitle(window, TITLE); } else printf("\n"); }
const Vect4 Vect4::operator/(const float scaler) const { return Vect4(x / scaler, y / scaler, z / scaler, w / scaler); }
const Vect4 Vect4::operator* (const double &rhs) { return Vect4( coord[0] * rhs, coord[1] * rhs, coord[2] * rhs); }