void PSLGSSkeleton::addTriangleMesh( const QPointF& p1, double t1, const QPointF& p2, double t2, const QPointF& p3, double t3 ) { double d = PSLGGraph::determinant( p1, p2, p3 ); if ( std::abs(d) < eps ) { return; } else if ( d > 0 ) { meshes.push_back( Triangle3D( QVector3D( p1.x(), p1.y(), t1 ), QVector3D( p2.x(), p2.y(), t2 ), QVector3D( p3.x(), p3.y(), t3 ) ) ); } else { meshes.push_back( Triangle3D( QVector3D( p3.x(), p3.y(), t3 ), QVector3D( p2.x(), p2.y(), t2 ), QVector3D( p1.x(), p1.y(), t1 ) ) ); } }
void PSLGSSkeleton::addTriangleMesh( PSLGVertex* v1, PSLGVertex* v2, const QPointF& p3, double t3 ) { double d = PSLGGraph::determinant( v1->oriPosition, v2->oriPosition, p3 ); if ( std::abs(d) < eps ) { return; } else if ( d > 0 ) { meshes.push_back( Triangle3D( QVector3D( v1->oriPosition.x(), v1->oriPosition.y(), v1->startTime ), QVector3D( v2->oriPosition.x(), v2->oriPosition.y(), v2->startTime ), QVector3D( p3.x(), p3.y(), t3 ) ) ); } else { meshes.push_back( Triangle3D( QVector3D( p3.x(), p3.y(), t3 ), QVector3D( v2->oriPosition.x(), v2->oriPosition.y(), v2->startTime ), QVector3D( v1->oriPosition.x(), v1->oriPosition.y(), v1->startTime ) ) ); } }
AIUnit::AIUnit(Vector3D pos, Scalar orient, Vector3D vel, Scalar rot, int size) //This constructor will initialize the values where //pos is a Vector for the triangle's position, //orient is its orientation in radians //vel is its initial velocity //rot is its initial angular velocity { body = Triangle3D(Vector3D(pos[X]+(20*cos(orient)),pos[Y]+(20*sin(orient)),0), Vector3D(pos[X]+(20*cos(orient+2.5)),pos[Y]+(20*sin(orient+2.5)),0), Vector3D(pos[X]+(20*cos(orient-2.5)),pos[Y]+(20*sin(orient-2.5)),0)); //Initializes a triangle using pos and orient kinematic = Kinematic(pos,orient,vel,rot); //Initializes the physics for the character appearance = Appearance(Color(1,0,0),true); //Starts the color as red steering = SteeringOutput(Vector3D(0,0,0),0.0); //Initializes the steering at zero steeringNum = 3; //Starts the steering with Blended Steering //Initialize the booleans defeatPlayer = false; dying = false; spawnNewAI = false; fast = false; wanderer = false; windowSize = size; //set the window size fsm = AI_FSM(); //Initialize the state machine }
void SSTask::drawMeshes3D( const QSizeF& mapSize ) const { QRectF boundingRect(QPointF( -mapSize.width()/2.0, -mapSize.height()/2.0), mapSize); glBegin(GL_TRIANGLES); mutex.lockForRead(); for(int i = 0; i < m_meshes_cache.size(); i++){ Triangle3D t = m_meshes_cache.at(i); if(!boundingRect.contains(t.v1.toPointF()) || !boundingRect.contains(t.v2.toPointF()) || !boundingRect.contains(t.v3.toPointF())) continue; QVector3D normal = QVector3D::crossProduct(t.v2 - t.v1, t.v3 - t.v1); if(normal.z() < 0){ t = Triangle3D(t.v3, t.v2, t.v1); normal.setZ( - normal.z()); } glNormal3d(normal.x(), normal.y(), normal.z()); glVertex3d(t.v1.x(), t.v1.y(), t.v1.z()); glVertex3d(t.v2.x(), t.v2.y(), t.v2.z()); glVertex3d(t.v3.x(), t.v3.y(), t.v3.z()); } mutex.unlock(); glEnd(); }
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nShowCmd) { INIT short State = 1; DWORD DefaultTime = timeGetTime(); CLSystem LSystem; CTriangle3D Triangle3D(L"Texture.jpg",3.0f); CCube3D Cube3D(L"Texture.jpg",3.0f); CPlane3D Plane3D(L"Grass.jpg",8.0f); LSystem.LoadFile("gfractal.ini"); CMandelbrot Mandelbrot; CMandelbrot3D Mandelbrot3D; Cube3D.Load(); BEGIN if(timeGetTime()-DefaultTime > 100){ if(Input.Keyboard(DIK_F1)&&State!=1&&State!=2){ UnloadAll(); Cube3D.Load(); State = 1; } if(Input.Keyboard(DIK_1)&&State!=1&&State==2){ UnloadAll(); Cube3D.Load(); State = 1; } if(Input.Keyboard(DIK_2)&&State==1&&State!=2){ UnloadAll(); Triangle3D.Load(); State = 2; } if(Input.Keyboard(DIK_F2)&&State!=3){ UnloadAll(); Plane3D.Load(); State = 3; } if(Input.Keyboard(DIK_F3)&&State!=4){ UnloadAll(); LSystem.Load(); State = 4; } if(Input.Keyboard(DIK_F4)&&State!=5){ UnloadAll(); Mandelbrot.Load(); State = 5; } if(Input.Keyboard(DIK_F5)&&State!=6){ UnloadAll(); Mandelbrot3D.Load(); State = 6; } DefaultTime = timeGetTime(); } if(State == 1) Cube3D.Update(); if(State == 2) Triangle3D.Update(); if(State == 3) Plane3D.Update(); if(State == 4) LSystem.Update(); if(State == 5) Mandelbrot.Update(); if(State == 6) Mandelbrot3D.Update(); END }
toxi::geom::Triangle3D toxi::geom::Triangle3D::createEquilateralFrom( Vec3D & a, Vec3D & b ) { Vec3D c = a.interpolateTo( b, 0.5 ); Vec3D dir = b.sub( a ); Vec3D n = a.cross( dir.normalize( ) ); c.addSelf( n.normalizeTo( dir.magnitude() * toxi::math::MathUtils::SQRT3 / 2 ) ); return Triangle3D( a, b, c ); }
void AIUnit::Update(Scalar delta_t,CharacterUnit& character,BlendedSteering* blender) //Updates the values for the character, with delta_t as //the amount of time passed since the last update and //character as the target for this character { int stateAction = fsm.update(delta_t); //update the state machine if(stateAction == 1) //If the action from the state machine is 1 dying = true; //Then the AI character should send a message that it needs to die if(stateAction == 2) //If the action from the state machine is 2 spawnNewAI = true; //Then the AI character should send a message that a new character should spawn Vector3D currentPos = kinematic.position; //the current position of the character //Create the different steering behavior objects Arrive arrive(*this,character); BlendedSteering* blend = blender; LookWhereYoureGoing look(*this); //Check each key to see which behavior to use and update the steering if (wanderer) steering = blend->GetSteering(); else steering = arrive.GetSteering(); kinematic.rotation = look.GetSteering().rotation; //Make sure the character looks where he is moving kinematic.Update(steering,delta_t); //Update the physics based on the steering Vector3D posDifference = kinematic.position - currentPos; //find the difference between the current position and the next position Translate(posDifference); //Translate the triangle that difference if (fast) { Translate(posDifference*0.75); kinematic.position += posDifference*0.75; } //Keep the character inside the game if (kinematic.position[X] < 20) kinematic.position[X] = 20; if (kinematic.position[X] > windowSize - 20) kinematic.position[X] = windowSize - 20; if (kinematic.position[Y] < 20) kinematic.position[Y] = 20; if (kinematic.position[Y] > windowSize - 20) kinematic.position[Y] = windowSize - 20; body = Triangle3D(Vector3D(kinematic.position[X]+(20*cos(kinematic.orientation)), kinematic.position[Y]+(20*sin(kinematic.orientation)),0), Vector3D(kinematic.position[X]+(20*cos(kinematic.orientation+2.5)), kinematic.position[Y]+(20*sin(kinematic.orientation+2.5)),0), Vector3D(kinematic.position[X]+(20*cos(kinematic.orientation-2.5)), kinematic.position[Y]+(20*sin(kinematic.orientation-2.5)),0)); //Update the triangle to render //If the character gets too close to the player, it kills the player if (abs((character.kinematic.position - kinematic.position).Length()) <= 40) defeatPlayer = true; }
Triangle3D get_largest_triangle(const Vector3Ds &points) { double max_dist = 0; Vector3Ds triple(3); for (unsigned int i = 0 ; i < points.size() ; i++) { for (unsigned int j = 0 ; j < points.size() ;j++) { double dist = algebra::get_squared_distance(points[i],points[j]); if (dist > max_dist) { max_dist = dist; triple[0] = points[i]; triple[1] = points[j]; } } } algebra::Segment3D seg(triple[0],triple[1]); max_dist=0; for (unsigned int i = 0 ; i < points.size();i++) { double dist = algebra::get_distance(seg,points[i]); if (dist > max_dist) { max_dist = dist; triple[2] =points[i]; } } return Triangle3D(triple[0],triple[1],triple[2]); }