HELP! 100 independently running Ramp objects

Hello :)
We would really like someone to have a look at the following code and tell us why it does not draw the animation or if it even is correct according to the assignment: We need to create a graphical animation that uses 100 independently running Ramp objects to perform animation, and we are really stuck with the program.

Please help to frustrated danish girls in desperate need of some help :)

#include "allocore/io/al_App.hpp"
#include "Ramp.h"
using namespace al;

class Shape{
public:
Mesh shape;
Ramp ramp;
Ramp rampPos;

Shape(){
//shape.reset();
shape.primitive(Graphics::LINES);
addSphere(shape, 0.2);
shape.color(HSV(0.6, 0.7, 1));
}
};

class MyApp : public App{
public:

Shape shapeball[100];
Ramp rampPos;
Vec3f posStart, posEnd;

MyApp(){

for(int i=0; i<100; ++i){
shapeball[i].rampPos.period(1.7);
}

nav().pos().set(0,0,4);
initWindow();
}

virtual void onAnimate(double dt){
for(int i=0; i<100; ++i){
shapeball[i].ramp.update(dt);
shapeball[i].shape.reset();
}

for(int i=0; i<100; ++i){
double _0to1 = double(i)/100;
double theta = 2 * _0to1 * 2*M_PI;
double zpos = shapeball[i].ramp.value();
zpos = 0.5;
theta *= shapeball[i].ramp.value() * zpos;

shapeball[i].shape.vertex(cos(theta), sin(theta), shapeball[i].ramp.value()*8 - 8);
shapeball[i].shape.color(HSV(_0to1, 0.8, shapeball[i].ramp.value()));

}

if(rampPos.update(dt)){
posStart = posEnd;
posEnd.set(
rnd::uniformS(),
rnd::uniformS(),
rnd::uniformS()
);
}
}

virtual void onDraw(Graphics& g, const Viewpoint& v){
for(int i=0; i<100; ++i){
g.pushMatrix(Graphics::MODELVIEW);
float frac = rampPos.value();
Vec3f pos = (posEnd-posStart) * frac + posStart;
g.translate(pos);
g.draw(shapeball[i].shape);
g.popMatrix();
}
}

};

int main(){
MyApp().start();
}
which language is it?
i mean coding.
Sounds like c++, aalok.

@Rie: It'd be nice if you put your code into code tags.

Doing the following:
[code]for(int a;;)[/code]

will transform into:
for(int a;;)
And will keep tabbing, giving our eyes better focus.

The problem here is we don't know your set-up.

1
2
#include "allocore/io/al_App.hpp"
#include "Ramp.h" 

Allocore is a publicly available library (on github, thanks Google).
But ramp.h? We have no idea what it has inside.

One of the common problems on similar setups could be:

1. Check if the window is redrawn.
Check if onDraw is ever called (Probably is).
2. Check if the backbuffer (if available) is swapped.
Do you need to call a command similar to g.EndDraw() , and you forgot about it?
3. Calculations
Calculations inside onAnimate could be wrong. Do a simpler calculation system work? Do simple examples work?

The problem isn't about the 100 objects to animate.
Just get a single one to animate, and you're done, adding the others won't be such a big problem compared to your current one.

EDIT: Fixed typo
Last edited on
Topic archived. No new replies allowed.