本文整理汇总了C++中ParticleManager类的典型用法代码示例。如果您正苦于以下问题:C++ ParticleManager类的具体用法?C++ ParticleManager怎么用?C++ ParticleManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParticleManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createString
// Create a particleGraph
ParticleGraph createString(glm::vec2 A, glm::vec2 B, glm::vec3 color, glm::vec3 headColor, uint32_t discFactor, ParticleManager& particleManager) {
glm::vec2 AB = B - A;
glm::vec2 step = glm::vec2(AB[0]/discFactor, AB[1]/discFactor);
glm::vec2 position = A;
float mass = 1.f;
ParticleGraph graph;
unsigned int id = 0;
for(int i = 0; i < discFactor + 1; ++i) {
id = particleManager.addParticle(mass, position, glm::vec2(0.f, 0.f), glm::vec2(0.f, 0.f), color, ParticleManager::Type::P_SNAKE);
if(id != 0) {
std::pair<unsigned int, unsigned int> pair (id, id - 1);
graph.push_back(pair);
}
else if(id == discFactor) {
std::pair<unsigned int, unsigned int> pair (id, 0);
graph.push_back(pair);
}
position += step;
}
particleManager.getParticleColor(0) = headColor;
return graph;
}
示例2: update
void StartMeny::update(){
mLoadButton->update();
for (std::vector<Button*>::iterator i = mButtons.begin(); i != mButtons.end(); i++){
(*i)->update();
}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::P)){
// StateManager::getInst().addState(new OptionsMeny);
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num1)){
// EventManager::getInst().addEvent("cutscene_intro");
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num2)){
// EventManager::getInst().addEvent("cutscene_2");
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num3)){
// EventManager::getInst().addEvent("cutscene_3");
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num4)){
// EventManager::getInst().addEvent("cutscene_ending");
//}
ParticleManager* particleManager = &ParticleManager::getInst();
particleManager->update();
}
示例3: isOutside
// Check if the snake is outside
bool isOutside(ParticleManager& snakeManager) {
for(int i = 0; i < snakeManager.getCount(); ++i) {
//Right
if(snakeManager.getParticleX(i) >= 1.f) {
return true;
}
// Left
if(snakeManager.getParticleX(i) <= -1.f) {
return true;
}
// Up
if(snakeManager.getParticleY(i) >= 1.f) {
return true;
}
// Down
if(snakeManager.getParticleY(i) <= -1.f) {
return true;
}
}
return false;
}
示例4: updateParticle
void updateParticle(ParticleManager& sourceManager, int sourceId, ParticleManager& destinationManager, int destinationId) {
destinationManager.getParticleMass(destinationId) = sourceManager.getParticleMass(sourceId);
destinationManager.getParticlePosition(destinationId) = sourceManager.getParticlePosition(sourceId);
destinationManager.getParticleVelocity(destinationId) = sourceManager.getParticleVelocity(sourceId);
destinationManager.getParticleForce(destinationId) = sourceManager.getParticleForce(sourceId);
destinationManager.getParticleColor(destinationId) = sourceManager.getParticleColor(sourceId);
}
示例5: glutDisplayFunc
/*-----------------------------------------------------------------------------------------------
Description:
This is the rendering function. It tells OpenGL to clear out some color and depth buffers,
to set up the data to draw, to draw than stuff, and to report any errors that it came across.
This is not a user-called function.
This function is registered with glutDisplayFunc(...) during glut's initialization.
Parameters: None
Returns: None
Exception: Safe
Creator: John Cox (2-13-2016)
-----------------------------------------------------------------------------------------------*/
void Display()
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// in the absence of an actual timer, use a hard-coded delta time
gParticleManager.Update(0.01f);
// this handles its own bindings and cleans up when it is done
gParticleManager.Render();
// tell the GPU to swap out the displayed buffer with the one that was just rendered
glutSwapBuffers();
// tell glut to call this display() function again on the next iteration of the main loop
// Note: https://www.opengl.org/discussion_boards/showthread.php/168717-I-dont-understand-what-glutPostRedisplay()-does
// Also Note: This display() function will also be registered to run if the window is moved
// or if the viewport is resized. If glutPostRedisplay() is not called, then as long as the
// window stays put and doesn't resize, display() won't be called again (tested with
// debugging).
// Also Also Note: It doesn't matter where this is called in this function. It sets a flag
// for glut's main loop and doesn't actually call the registered display function, but I
// got into the habbit of calling it at the end.
glutPostRedisplay();
}
示例6: if
void Graphics::CallSpawnFunction(SpawnMessage* spawn)
{
//relevant ifs to determine spawn type
if (spawn->type == EntityID::Icecream)
{
GraphicsComponent *gcp = new GraphicsComponent;
gcp->SetComponentId(CompID::Graphics);
//gcp->type = EntityID::Icecream;
gcp->trans = spawn->trans;
gcp->SetOwner(spawn->owner);
//pushes GCP, into the entity components
//that was passed in through the message.
spawn->components->push_back(gcp);
TexInstances[spawn->entid] = gcp;
}
else if (spawn->type == EntityID::ParticleGroup)
{
/*ParticleGroup *gcp;
if (spawn->info == NULL)
gcp = new ParticleGroup(1.0f,0.f,0.f, 30);
else
{
std::cout << (((float *)spawn->info)[4]);
gcp = new ParticleGroup((((float *)spawn->info)[1]), (((float *)spawn->info)[2]), (((float *)spawn->info)[3]),
(((float *)spawn->info)[4]), (((float *)spawn->info)[5]));
//gcp = new ParticleGroup;
}
gcp->SetComponentId(CompID::ParticleGroup);
//gcp->type = EntityID::ParticleGroup;
gcp->trans = spawn->trans;
gcp->SetOwner(spawn->owner);
spawn->components->push_back(gcp);*/
//NonTexInstances.push_back(gcp);
}
else if (spawn->type == EntityID::ParticleManager)
{
ParticleManager<ParticleGroup> *pcp = new ParticleManager<ParticleGroup>;
pcp->trans = spawn->trans;
pcp->SetOwner(spawn->owner);
spawn->components->push_back(pcp);
for (int i = 0; i < 50; ++i)
pcp->AddParticle(new ParticleGroup(100));
NonTexInstances[spawn->entid] = pcp;
}
else if (spawn->type == EntityID::ParticleSystem)
{
ParticleSystem * psys = new ParticleSystem;
psys->trans = spawn->trans;
psys->SetOwner(spawn->owner);
spawn->components->push_back(psys);
NonTexInstances[spawn->entid] = psys;
}
};
示例7: ParticleManager
ParticleManager* ParticleManager::create() {
ParticleManager* ret = new ParticleManager();
if (ret && ret->init()) {
ret->autorelease();
}
else {
CC_SAFE_DELETE(ret);
}
return ret;
}
示例8: addAttractiveForce
// Add attractive force
void addAttractiveForce(ParticleManager& foodManager, ParticleManager& snakeManager) {
int attractiveCoeff = 50;
glm::vec2 attractiveForce = foodManager.getParticlePosition(0) - snakeManager.getParticlePosition(0);
float d = glm::length(attractiveForce);
attractiveForce = glm::normalize(attractiveForce);
// Plus on divise et plus c'est petit : pluattractivecoeff augmente et mois l'attraction est forte au loin
snakeManager.addForceToParticle(0, glm::vec2(attractiveForce[0]/(attractiveCoeff*d), attractiveForce[1]/(attractiveCoeff*d)));
}
示例9: addParticletoSnake
// Add a particle to the Snake
void addParticletoSnake(ParticleGraph& graph, int id, ParticleManager& foodManager, ParticleManager& snakeManager) {
id = snakeManager.addParticleToHead(foodManager.getParticleMass(id),
foodManager.getParticlePosition(id),
foodManager.getParticleVelocity(id),
foodManager.getParticleForce(id),
snakeManager.getHeadColor());
foodManager.clear();
std::pair<unsigned int, unsigned int> pair (id, snakeManager.getCount() - 2);
graph.push_back(pair);
snakeManager.getParticleColor(1) = snakeManager.getParticleColor(2);
}
示例10: configuration
/*-----------------------------------------------------------------------------------------------
Description:
Governs window creation, the initial OpenGL configuration (face culling, depth mask, even
though this is a 2D demo and that stuff won't be of concern), the creation of geometry, and
the creation of a texture.
Parameters:
argc (From main(...)) The number of char * items in argv. For glut's initialization.
argv (From main(...)) A collection of argument strings. For glut's initialization.
Returns:
False if something went wrong during initialization, otherwise true;
Exception: Safe
Creator: John Cox (3-7-2016)
-----------------------------------------------------------------------------------------------*/
void Init()
{
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CCW);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LEQUAL);
glDepthRange(0.0f, 1.0f);
GLuint particleProgramId = GenerateVertexShaderProgram();
GLuint computeProgramId = GenerateComputeShaderProgram();
// all values are in windows space (X and Y limited to [-1,+1])
// Note: Toy with the values as you will.
//unsigned int totalParticles = 20000;
unsigned int totalParticles = 600000;
unsigned int maxParticlesEmittedPerFrame = 200;
glm::vec2 center = glm::vec2(+0.3f, +0.3f);
float radius = 1.1f;
float minVelocity = 0.05f;
float maxVelocity = 0.6f;
gParticleManager.Init(particleProgramId,
computeProgramId,
totalParticles,
maxParticlesEmittedPerFrame,
center,
radius,
minVelocity,
maxVelocity);
}
示例11: render
void StartMeny::render(){
sf::RenderWindow* window = WindowManager::getInst().getWindow();
window->draw(mBackground);
window->draw(mLoadButton->getSprite());
for (std::vector<Button*>::iterator i = mButtons.begin(); i != mButtons.end(); i++){
window->draw((*i)->getSprite());
}
ParticleManager* particleManager = &ParticleManager::getInst();
particleManager->render(*window);
}
示例12: copyParticle
// Copy a particle
int copyParticle(ParticleManager& sourceManager, ParticleManager& destinationManager, int id) {
int newId = destinationManager.addParticle(sourceManager.getParticleMass(id),
sourceManager.getParticlePosition(id),
sourceManager.getParticleVelocity(id),
sourceManager.getParticleForce(id),
sourceManager.getParticleColor(id));
return newId;
}
示例13: addRepulsiveForce
// Add repulsive force
void addRepulsiveForce(ParticleManager& repulsiveManager, ParticleManager& snakeManager) {
if(repulsiveManager.getCount() > 0) {
for(int i = 0; i < snakeManager.getCount(); ++i) {
for(int j = 0; j < repulsiveManager.getCount(); ++j) {
glm::vec2 repulse = snakeManager.getParticlePosition(i) - repulsiveManager.getParticlePosition(j);
float d = glm::length(repulse);
repulse = glm::normalize(repulse);
int repulsiveCoeff = 40;
if(d < 0.2) {
// Plus on divise et plus c'est petit : pluattractivecoeff augmente et mois l'attraction est forte au loin
snakeManager.addForceToParticle(i, glm::vec2(repulse[0]/(repulsiveCoeff*d), repulse[1]/(repulsiveCoeff*d)));
}
}
}
}
}
示例14: apply
void ConstantForce::apply(ParticleManager &pm) {
unsigned int count = pm.getSize();
for(int i = 0; i < count; ++i){
pm.addForce(i, m_force);
}
}
示例15: addBonus
// Create bonus
void addBonus(ParticleManager& bonusManager) {
bonusManager.removeParticle(0);
bonusManager.addRandomParticle(1, ParticleManager::Type::P_BONUS);
}