void AqueousNaClGenerator::addMolecule(double x, double y, double z, unsigned long id, int cid, ParticleContainer* particleContainer) { std::cout << "Add molecule at " << x << ", " << y << ", " << z << " with cid=" << cid << endl; vector<double> velocity = getRandomVelocity(_temperature); //double orientation[4] = {1, 0, 0, 0}; // default: in the xy plane // rotate by 30° along the vector (1/1/0), i.e. the angle bisector of x and y axis // o = cos 30° + (1 1 0) * sin 15° double orientation[4]; getOrientation(15, 10, orientation); double I[3] = {0.,0.,0.}; I[0] = _components[cid].I11(); I[1] = _components[cid].I22(); I[2] = _components[cid].I33(); /***** Copied from animake - initialize anular velocity *****/ double w[3]; for(int d=0; d < 3; d++) { w[d] = (I[d] == 0)? 0.0: ((randdouble(0,1) > 0.5)? 1: -1) * sqrt(2.0* randdouble(0,1)* _temperature / I[d]); w[d] = w[d] * MDGenerator::fs_2_mardyn; } /************************** End Copy **************************/ Molecule m(id, &(_components[cid]), x, y, z, // position velocity[0], -velocity[1], velocity[2], // velocity orientation[0], orientation[1], orientation[2], orientation[3], w[0], w[1], w[2] ); particleContainer->addParticle(m); }
Asteroid::Asteroid() : m_StartPosition(getRandomPosition()) , m_Velocity(getRandomVelocity()) , m_RotationSpeed(getRandomRotationSpeed()) , m_Speed(getRandomSpeed()) , m_Type(getRandomType()) , m_HasBeenStruck(false) { setupSprite(); setupShape(); }
Asteroid::Asteroid(const glm::vec2& position, AsteroidType::Type type) : m_StartPosition(position) , m_Velocity(getRandomVelocity() * SUB_ASTEROID_VELOCITY_FACTOR) , m_RotationSpeed(getRandomRotationSpeed() * SUB_ASTEROID_ROTATION_SPEED_FACTOR) , m_Speed(getRandomSpeed() * SUB_ASTEROID_SPEED_FACTOR) , m_Type(type) , m_HasBeenStruck(false) { setupSprite(); setupShape(); }
void Solver::initializeParticles() { // Initialize the swarms best position with the lowest value. for (auto &i : swarm.getParticles()) { Solution position = getRandomSolution(); Velocity velocity = getRandomVelocity(); i.setPosition(position); i.setVelocity(velocity); // Fitness value / Profit of the solution/position. int profit = calculateProfit(position); profit -= calculatePenalty(position, profit); i.setBestPositionAndValue(position, profit); // Check if this solution is better than the global solution. if (!swarm.isGBestInitialized()) swarm.setBestPositionAndValue(position, profit); else if (profit > swarm.getBestValue()) swarm.setBestPositionAndValue(position, profit); } }
int main(void) { // seed pseudorandom number generator srand48(time(NULL)); // instantiate window GWindow window = newGWindow(WIDTH, HEIGHT); // instantiate bricks initBricks(window); // instantiate ball, centered in middle of window GOval ball = initBall(window); // instantiate paddle, centered at bottom of window GRect paddle = initPaddle(window); // instantiate scoreboard, centered in middle of window, just above ball GLabel label = initScoreboard(window); // number of bricks initially int bricks = COLS * ROWS; // number of lives initially int lives = LIVES; // number of points initially int points = 0; double x_velocity = getRandomVelocity(); double y_velocity = 0.05; GObject collision; char label_text[20]; snprintf(label_text, 20, "Score: %d", points); setLabel(label, label_text); waitForClick(); // keep playing until game over while (lives > 0 && bricks > 0) { move(ball, x_velocity, y_velocity); collision = detectCollision(window, ball); if (getX(ball) + getWidth(ball) >= getWidth(window)) x_velocity *= -1; else if (getX(ball) <= 0) x_velocity *= -1; if (collision == paddle) y_velocity *= -1; else if (collision != NULL && strcmp(getType(collision), "GRect") == 0) { bricks--; points++; snprintf(label_text, 10, "Score: %d", points); setLabel(label, label_text); y_velocity *= -1; removeGWindow(window, collision); } if (getY(ball) + getHeight(ball) >= getHeight(window)) { lives--; if (lives == 0) break; setLocation(ball, (WIDTH - RADIUS)/2, (HEIGHT - RADIUS)/2); x_velocity = getRandomVelocity(); waitForClick(); } else if (getY(ball) <= 0) y_velocity *= -1; GEvent event = getNextEvent(MOUSE_EVENT); if (event != NULL) { if (getEventType(event) == MOUSE_MOVED) { double x = getX(event) - PADDLE_WIDTH/2; double y = getY(paddle); if (x >= 0 && x + PADDLE_WIDTH <= WIDTH) setLocation(paddle, x, y); } } } // wait for click before exiting waitForClick(); // game over closeGWindow(window); return 0; }