C++

Miscellaneous Forums/General Discussion/C++

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

alright, new problem.

I've been sitting here trying to get this to work for hours, maybe one of you guys knows what i'm doing wrong:

Problem: It's not drawing anything, what??

c++
#include <math.h>
#define DEG_TO_RAD 0.0174532925199432957692369076848861

//Functions to grab a Radian sin/cos not in degrees.
double Sin2( double ang ){
	return sin( ang*DEG_TO_RAD );
}
double Cos2( double ang ){
	return cos( ang*DEG_TO_RAD );
}

// All the stuff that can be accessed in bmax
extern "C" {

    // our particle class
    class cParticle {
    public:
          // all the variables associated with a particle
          float x;
          float y;
          float a;
          int r;
          float dx;
          float dy;
          float da;
          int maxdistance;
          float speed;
          int dir;
          int fade;
          int z;
          
          // constructor (AKA Create())
          cParticle(float, float, int, float, int, bool, bool, int);
          // destructor have not found a use yet
          ~cParticle();
          
          //Update particle
          void Update(void); 
    };
    
    // Our class functions redefined:
           
    // constuctor
    cParticle::cParticle(float _x, float _y, int _dir = 0, 
                               float _speed = 0, 
                          int frames = 1, bool _fade = false, 
                          bool _autorot = false, int _z = 0) {
                
  		z = _z;
		x = _x;
		y = _y;
		speed = _speed;
		dir = _dir;
		dx = (Sin2(dir) * speed); 
		dy = (-Cos2(dir) * speed);
		da = 1.0 / frames;
		maxdistance = frames;
		if(dir > 0&&_autorot > 0){
			r = -dir - 180;
		}

		if(_fade > 0) {
			fade = true;
        }
                               
    
    }
    //destructor
    cParticle::~cParticle() {
        
        // code for destructor
    }      
    
             
    void cParticle::Update() {
		x=x+dx;
		y=y+dy;
    }
    
    
    // mainsteam functions:
                 
    // Wrap function to create a particle
    cParticle *cCreateParticle(float _x, float _y, int _dir = 0, 
                               float _speed = 0, 
                          int frames = 1, bool _fade = false, 
                          bool _autorot = false, int _z = 0) {
         cParticle *p; // particle that we will return
         p = new cParticle(_x, _y, _dir, 
                           _speed, frames, 
                           _fade, 
                           _autorot, _z); // basicly shove the arguments of this function into a constructor
         return p;
    }
    
    //Wrap function to delete a particle
    void cDeleteParticle(cParticle *p) {
         delete p;
    }
    
    //Wrap function to update a particle
    void cUpdateParticle(cParticle *p){
         p->Update();
    }
    
    //functions to get various states of a particle
    float cPX(cParticle *p) {
          return p->x;
    }
    float cPY(cParticle *p) {
          return p->y;
    }
    float cPA(cParticle *p) {
          return p->a;
    }
}


bmax
SuperStrict

Import "main.cpp"

'Wrap functions from the particle C++ code
Extern "C"
	Function cCreateParticle:Byte Ptr(_x:Int, _y:Int, _dir:Int = 0, _speed:Float = 0, frames:Int = 1, _fade:Int = False, _autorot:Int = False, _z:Int = 0)
	Function cUpdateParticle(p:Byte Ptr)
	Function cDeleteParticle(p:Byte Ptr)
	Function cPX(p:Byte Ptr)
	Function cPY(p:Byte Ptr)
	Function cPA(p:Byte Ptr)
End Extern

'TParticle type, basicly a wrapper w/ drawing functions for the class counterpart.
Global ParticleList:TList = CreateList()
Type TParticle
	Field img:TImage
	Field cBuddy:Byte Ptr
	
	
	Method Create:TParticle(_x:Int, _y:Int, _img:TImage, _dir:Int = 0, _speed:Float = 0, frames:Int = 1, _fade:Int = False, _autorot:Int = False, _z:Int = 0)
		'create a "c" particle and give it's handle to the cbuddy variable
		cBuddy = cCreateParticle(_x, _y, _dir, _speed, frames, _fade, _autorot, _z)
		'Add this object to the particle list
		ListAddLast(ParticleList,Self)
		'Add given image to the object
		img = _img
	End Method
	
	Method Update()
		'Update the "c" particle
		cUpdateParticle(cBuddy)
		'Grab the new x/y positions of the "c" particle(so we only have to use this function once per loop)
		Local x:Float = cPX(cBuddy)
		Local y:Float = cPY(cBuddy)
		'Draw the given img at the "c" Particle's locations 
		DrawImage img,x,y
	End Method
	
End Type


'init graphics
AppTitle = "C++ Particle Test"
Graphics 800,600


'Create Dot image
Local dot:Timage = CreateImage(10,10)
DrawOval 0,0,10,10
GrabImage dot,0,0

'main loop
While Not KeyHit(KEY_ESCAPE)
Cls

	'create a particle at the mouse's location, then update all particles
	Local part:TParticle = New TParticle.Create(MouseX(),MouseY(),dot)
	For Local i:TParticle = EachIn ParticleList
		i.Update()
	Next

Flip 1
Wend

End


Now I think this is on the blitzmax side, because even if the C++ side was screwed, it would still return '0' on the position code, thus it would at least draw a circle at 0,0 right? well, its not, and I cant figure out why, because the List/Bmax TParticle looks correct.