Hi, im making a list where I store my objects and run through them in order to calculate a few physics for them, here is the main source code
#include "ph1.h"
#include "timer.h"
#include "objeto.h"
#include "vector.h"
#include <iostream>
using namespace std;
int main()
{
PH1 sim;
Timer myTimer;
myTimer.start();
sim.AddObject(Objeto(5.0f, Vector(0,0,0), Vector(1,0,0), Vector(0,0,0)));
sim.AddObject(Objeto(5.0f, Vector(0,0,0), Vector(1,2,0), Vector(0,0,0)));
for(int i = 1; i < 3; i++)
{
sim.RunPh1(myTimer.ellapsed()); //run the simulation
sim.cabeza.pos.toString(); //print the position information
}
}
So the problem comes when i run RunPh1, because i think im not adding correctly the objects.
here is ph1.cpp
#include "objeto.h"
#include "ph1.h"
#include <iostream>
PH1::PH1()
{
cabeza.siguiente=NULL;
count = 0;
}
void PH1::AddObject(Objeto nuevo)
{
if(count == 0)
{
cabeza = nuevo;
count = 1;
std::cout << cabeza.siguiente << std::endl;
}
else
{
temporal = cabeza;
while(temporal.siguiente != NULL)
{
if(temporal.siguiente != NULL) temporal = *temporal.siguiente;
}
temporal.siguiente = &nuevo;
count++;
}
}
void PH1::RunPh1(float dt)
{
std::cout << "time: " << dt << std::endl;
temporal = cabeza;
do
{
temporal.vel+=(temporal.force / temporal.m) * dt;
temporal.pos+= (temporal.vel * dt);
if(temporal.siguiente != NULL) temporal = *temporal.siguiente;
}
while(temporal.siguiente != NULL);
}
I think my addobject method is not adding in new list items correctly, i know its a lot to go through it but if anyone takes their time i will be very grateful. NOTE: cabeza means head (of the list)