Sign in to follow this  
  • entries
    4
  • comment
    1
  • views
    2,757

Entries in this blog

aiaf

Draws a box from one vector to another.

To be used as some kind of arrow.

 

Need feedback if its a better way to do this, but so far seem to be ok for my purposes.

 

Example usage:

ArrowUi *t = new ArrowUi(Vec3(0.0, 0.0, 0.0), testshadow->GetModel()->GetPosition());

 

class ArrowUi {
   private:
    Model *model;
    Entity *pivot;
    Vec3 from;
    Vec3 to;
    float distance;
   public:
    ArrowUi();
    ArrowUi(Vec3 from, Vec3 to);
    void From(Vec3 from);
    void To(Vec3 to);
    void Draw();
};


ArrowUi::ArrowUi() {
   model = NULL;
   surface = NULL;
   pivot = NULL;
   from = NULL;
   to = NULL;
}

ArrowUi::ArrowUi(Vec3 from, Vec3 to) {
   this->from = from;
   this->to = to;
   Draw();
}

void ArrowUi::From(Vec3 from) {
   this->from = from;
}

void ArrowUi::To(Vec3 to) {
   this->to = to;
}

void ArrowUi::Draw() {
   pivot = Pivot::Create();
   pivot->SetPosition(from, true);

   distance = from.DistanceToPoint(to);
   model = Model::Box(0.05, 0.05, distance, pivot);
   model->Move(0, 0, distance/2);

   pivot->AlignToVector(to - from, 0);
   pivot->AlignToVector(to - from, 1);
   pivot->AlignToVector(to - from, 2);
}

aiaf

Want to share this maybe will help someone.

 

Its pretty basic but it has missile effect by distance and at certain time.

Should be easy to extend.

 

trigger the missile:

 

tm3 = new Missile(Vec3(5.0f, 5.0f, 0.0f));
tm2 = new Missile(Vec3(0.0f, 0.0f, 0.0f), tm3->GetPosition(), true);

 

and call the Loop method in the game loop

 

#ifndef __S_MISSILE_H__
#define __S_MISSILE_H__
#include "Leadwerks.h"

using namespace Leadwerks;
class Missile {
private:
 Emitter *mem;
 Material* unitexpmat;
 Model *model;
 Vec3 targetDirection;
 float mass;
 long creationTime;
 long detonationTime;
 void Init();
 void Effect(Material* mat);
public:
 Missile();
 Missile(Vec3 pos);
 Missile(Vec3 pos, Vec3 targetDirection, bool launch);
 void SetDetonationTime(long detonationTime);
 void SetPosition(Vec3 pos);
 void SetDirection(Vec3 targetDirection);
 void SetMass(float mass);
 Vec3 GetPosition();
 Vec3 GetTargetPosition();
 void Launch();
 void Loop(Material* mat);
};
#endif

 

#include "Missile.h"
void Missile::Init() {
model = Model::Box(0.1, 0.1, 0.1);
model->SetColor(0.1, 0.1, 0.1);
mass = 0.01;
model->SetMass(mass);
model->SetGravityMode(false);
Shape* shape = Shape::Box(0,0,0,0,0,0,0.1, 0.1, 0.1);
model->SetShape(shape);
shape->Release();
creationTime = Time::Millisecs();
detonationTime = -1;
}
Missile::Missile() {
Init();
}
Missile::Missile(Vec3 pos, Vec3 direction, bool launch) {
Init();
SetPosition(pos);
SetDirection(direction);
if(launch == true) {
 model->AddForce(direction[0], direction[1], direction[2], true);
}
}
Missile::Missile(Vec3 pos) {
Init();
SetPosition(pos);
}
void Missile::SetPosition(Vec3 pos) {
model->SetPosition(pos);
}
void Missile::SetDirection(Vec3 targetDirection) {
this->targetDirection = targetDirection;
}
void Missile::SetMass(float mass) {
this->mass = mass;
}
void Missile::SetDetonationTime(long detonationTime) {
this->detonationTime = (creationTime + detonationTime);
}

Vec3 Missile::GetPosition() {
return model->GetPosition();
}
Vec3 Missile::GetTargetPosition() {
return targetDirection;
}
void Missile::Launch() {
model->AddForce(targetDirection[0], targetDirection[1], targetDirection[2], false);
}
void Missile::Effect(Material* mat) {
 Vec3 nd = targetDirection.Normalize();
 mem = Emitter::Create(200);
 mem->SetMaterial(mat);
 mem->SetEmissionShape(1);
 mem->SetEmissionVolume(Vec3(.50,.50,.50));
 mem->SetDuration(300);
 mem->SetVelocity(nd[0],nd[1],nd[2],0);
 mem->SetColor(.30,.0,.0,.5,0);
 mem->SetColor(.20,.10,.10,0.4,1);
 mem->AddScaleControlPoint(0,0);
 mem->AddScaleControlPoint(.9,3);
 mem->AddScaleControlPoint(0.1,0);
 mem->SetLoopMode(false);
}
void Missile::Loop(Material* mat) {
if(detonationTime > 0) {
 if(Time::Millisecs() >= detonationTime) {
	 Effect(mat);
	 mem->SetPosition(GetPosition()[0], GetPosition()[1], GetPosition()[2],true);
	 model->Hide();
	 detonationTime = -1;
 }
}
else {
 if(model->GetPosition().DistanceToPoint(targetDirection) < 0.5) {
	 Effect(mat);
	 mem->SetPosition(targetDirection[0], targetDirection[1], targetDirection[2],true);
	 model->Hide();
 }
}
}

aiaf

I just updated my laptop to ubuntu 15.10 (from 15.04).

 

And got into some intereasting issues.

 

I rebuild my game with the new compiler, and it doesnt link anymore.

 

I got a bunch of undefined references like below:

 

undefined reference to `Leadwerks::Window::Create(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int, int, int, int)'

 

This didnt make any sense, the program was linking just fine with the previous version of gcc (4.9.2).

 

After some digging i found the explanation:

 

https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html

 

It seems in gcc 5.1 a new abi was introduced, and the Leadwerks static lib was built with some previous version causing the above problems.

 

The solution i used was to add this macro at the begining of every cpp file in the project (in case of linux)

 

#define _GLIBCXX_USE_CXX11_ABI 0

 

Ths forces the use of the old abi and the game links just fine.

 

I suppose this wont be really a problem for Leadwerks, but was annoying to me.

 

Regards

aiaf

Just started with Leadwerks.Heres a way to build a c++ project using cmake on linux.

 

Start from an existing project (lets call it Proj):

 

Copy

~/.steam/steamapps/common/Leadwerks

into Source/Libs.

Now you have Proj/Source/Libs/Leadwerks (this directory contains all the header files and static libs needed).

 

Can use this Libs dir to add any other external libs you need.

 

Here is the CMakeLists.txt:

https://github.com/aiafrasinei/lep.git

 

Copy to the root of the project.

cmake . and make

 

 

Will work on windows also with some modifications.

 

~/Documents/Leadwerks/Projects/test/Projects/Linux/Proj check the codeblocks project (Proj.cbp, Proj.depend) if you need to add more to the CMakeLists.txt

 

Hope this helps

Sign in to follow this