well after adding this line of code into the draw function, nothing gets rendered..
anyways this is a bit source code... the question is, how do i sync the actor of the class with the pos / matrix ?
actually if i need a matrix or a position i take the actors one... i guess i have to sync those values so i can do this.pos() to get the real position or this.matrix() to get the matrix...
i guess i did something wrong here...
another question: my rotation axis of my actor is not right as in the mesh editor / object editor.. is it possible to fix it, how could it happen?
last thing: i want to create a addforce bomb so every actor in the radius of the bomb should apply forces i guess by substr. those positions (bomb and the target), normalize and multiply by intensity float!?
actually i iterate through all ships in this case, but how should the loop look like? should i do it this way?
pseudocode:
Code:
void ForceBomb(Vec pos, flt radius, flt energy)
{
REPA(ships)
{
if(Dist(pos, ships[i].pos) <= radius)
{
Vec tmpos = bomb.pos() - ships[i].pos();
tmpos.normalize();
tmpos.mul(energy);
ships[i].actor.addforce(tmpos);
}
}
}
Thank you for your help!
/******************************************************************************/
#include "stdafx.h"
/******************************************************************************/
/*******************************************************************************************
* Tauri Defense Mine Class
* written by Tim Koepsel <tim.koepsel@xzessmedia.de>
*******************************************************************************************/
class Mine : public Game::Obj
{
public:
Mine();
~Mine();
void create(Game::ObjParams &obj);
bool update();
uint drawPrepare();
void drawShadow();
void draw2D();
Actor* getActor() { return &actor; }
Matrix getactormatrix();
Vec getactorpos();
int getspeed();
virtual Vec pos ( ) { return _matrix.pos ;} // get position
virtual Matrix matrix ( ) { return _matrix ;} // get matrix
Matrix matrixscaled( ) { return _matrixscaled ;} // get matrix
virtual void pos (C Vec &pos ) { _matrix.pos = pos; _matrixscaled.pos = pos; } // set position
virtual void matrix(C Matrix &matrix) { _matrix = matrix; _matrixscaled = _matrix; _matrixscaled.scaleOrn(scale); } // set matrix, for most classes 'matrix' should be normalized
private:
Matrix _matrix;
Matrix _matrixscaled;
Vec scale;
MeshPtr mesh;
MaterialPtr material;
PhysBodyPtr phys;
Actor actor;
bool isAlive;
// Custom Parameters
Str shipname;
int hull;
int shield;
int attack;
int defense;
int speed;
flt angle;
bool isPlayer;
}
Mine::Mine()
{
// Read Custom Parameters
shipname = "Unbenannt";
hull = 10;
shield = 10;
attack = 10;
defense = 10;
angle = 0;
speed = 5;
isAlive = true;
isPlayer = false;
}
Mine::~Mine()
{
}
void Mine::create(Game::ObjParams &obj)
{
scale = obj.scale3();
mesh = obj.mesh();
material = obj.material();
phys = obj.phys();
_matrix = obj.matrixFinal().normalize();
_matrixscaled = _matrix;
_matrixscaled.scaleOrn(scale);
angle = Angle(obj.matrixFinal().z.xz())-PI_2;
speed = 5;
if(phys)
{
actor.create(*phys, 1, scale).matrix(_matrix);
actor.obj(this);
actor.group(AG_MINE);
}
// Read Custom Parameters
if(Param *par=obj.findParam(L"schiffname" ))shipname =par->asText();
if(Param *par=obj.findParam(L"huelle"))hull=par->asInt ();
if(Param *par=obj.findParam(L"angriff"))attack=par->asInt ();
if(Param *par=obj.findParam(L"verteidigung"))defense=par->asInt ();
if(Param *par=obj.findParam(L"schild"))shield=par->asInt ();
if(Param *par=obj.findParam(L"maxspeed"))speed=par->asFlt();
if(Param *par=obj.findParam(L"isPlayer"))isPlayer=par->asBool();
}
void Mine::draw2D()
{
//getactormatrix().draw();
actor.matrix().normalize().axis().drawP(RED, 0.005);
_matrixscaled.axis().drawP(BLUE, 0.005);
}
Bool Mine::update()
{
if(T.actor.cuts(AG_SHIP) || T.actor.cuts(AG_ASTEROID) || T.actor.cuts(AG_PLANET) || T.actor.cuts(AG_STATION))
{
// BOMB
}
if(Dist(playership.pos(), T.pos()) < 15)
{
// If Player is near mine
Vec dir = playership.pos()-T.pos();
dir.normalize();
T.actor.addVel(dir*1.5);
}
_matrixscaled.normalize();
actor.matrix().normalize();
return isAlive;
if(hull == 0)
{
isAlive = false;
return isAlive;
}
}
uint Mine::drawPrepare()
{
if(mesh && Frustum(mesh->box, actor.matrix().normalize()))
{
MaterialLock = material();
mesh->draw(getactormatrix());
MaterialLock = NULL;
}
return NULL;
}
void Mine::drawShadow()
{
if(mesh && Frustum(mesh->box, actor.matrix().normalize()))
{
MaterialLock = material();
mesh->drawShadow(getactormatrix());
MaterialLock = NULL;
}
}
Matrix Mine::getactormatrix()
{
Matrix m = actor.matrix().normalize();
return m;
}
Vec Mine::getactorpos()
{
Vec m = actor.pos();
return m;
}
int Mine::getspeed()
{
return speed;
}
void ForceBomb(Vec pos, flt radius, flt energy)
{
REPA(Ships)
{
}
}