Jump to content

  • Log In with Google      Sign In   
  • Create Account


BaneTrapper

Member Since 04 Jul 2012
Offline Last Active Yesterday, 06:37 AM
-----

Topics I've Started

How to get float value that is less then 1 without the higher part

Yesterday, 06:35 AM

Hello.

I am kinda rusty in language so il just make example code;

I need this

float number = 1.332;
float newNumber = RemoveBigNumber(number);
//newNumber = 0.332;

what is the std function for such a method? i cant find it in

http://www.cplusplus.com/reference/cmath/


Triangle and rectangle intersect find position points of rectangle that intersect

15 April 2014 - 01:37 PM

Hello.

I have this image first:

Notice:

1:Triangle

2:Rectangle

3:Two green dots

Untitled.png

How do i find the two green dots position if objects exist in 2d space?

 

What i have is a triangle that at one point will be colliding with rectangle and i need to remove the part of the triangle that is colliding with rectangle, to do such i thought about making few triangles from the existing triangles.

 

I need to end up with following triangles.

Untitled2.png

The issue is i do not know how to get the green positions on the rectangle if someone would be kind to provide any kind of help or hints i would be glad i do not know from where to start.

 

Edit::
I made a example to show what i need calculated

Example.png

I want to write function as:

void Generate_Intersetion_Points(sf::Vector4i rec, sf::Vector2i line, std::Vector<sf::Vector2i> & generatedPointsPosition);

The function would take rectangle and a line and feed intersection point intro the vector, the issue is i don't know the math required, some hints would be great to start with.


Making a copy of object from a pointer but dont know its type

14 April 2014 - 07:00 AM

Hello.

In the main where i make a copy of above objects(bellow that comment) i don't know how to determinate what type the object it is so i wrote (a) for this example

[code]
class a
{
public:
    virtual void Print();
};

class b : public a
{
public:
    void Print();
};

class c : public a
{
public:
    void Print();
};
//////////////////////////////////////////
void a::Print()
{
    std::cout<<"a"<<std::endl;
}
void b::Print()
{
    std::cout<<"b"<<std::endl;
}
void c::Print()
{
    std::cout<<"c"<<std::endl;
}
//////////////////////////////////////////
int main()
{
    std::unique_ptr<a> objA1 = std::unique_ptr<a>(new b);
    std::unique_ptr<a> objA2 = std::unique_ptr<a>(new c);
    //Make a copy of above objects
    std::unique_ptr<a> objA3 = std::unique_ptr<a>(new a/*this a i do not know to to determinate its type*/(*objA1));
    std::unique_ptr<a> objA4 = std::unique_ptr<a>(new a/*also this a i do not know to to determinate*/(*objA2));

    objA1->Print();
    objA2->Print();
    objA3->Print();
    objA4->Print();

    system("pause");
    return 0;
};
[/code]

Output is

b
c
a
a

But i need it to be (b c b c) how can i achieve that?


Error from/with unique_ptr trying to acces private member, error C2248

13 April 2014 - 02:01 PM

Hello, i was doing work on my game and i stumbled upon a problem i cant resolve.

I want to be able to assign NewUnit = OldUnit

Commenting one line makes the error go away, thus i am suspecting that is the issue, but i do not know how to resolve.

class Item

{

public:

    Item();

    virtual void AddToInventory();

    virtual void AddToTown();

    virtual void PrintData();

};
class Bag

{

public:

    Bag();

    int bagMaxSize;

    std::vector<std::unique_ptr<Item>> itemList;

};



class InventoryForUnits

{

public:

    InventoryForUnits();

    //void AddBag(Bag & BagTMP);

    //void AddItemToBag(int bagID, Item & item);

    //void PrintData();



    int bagMaxAmount;

    std::vector<Bag> bagList;//Comenting this line makes the error not appear

};
//Somewhere in Unit.h
class Unit
{
public:
InventoryForUnits inventory;
}
//Somewhere in unit.cpp
int UnitList::AddUnit(Unit & objUnit)//Returns index of unit added
{
//Check if can pick from empty pos in vector
    if(emptyUnitListPos.size() > 0)
    {
        const int id = emptyUnitListPos.size()-1;
        unitList[id] = objUnit;
        unitList[id].isInUse = true;//This is set with the new object passed in anyway
        objEntity.AddUnitEntity(unitList[id].entitySetting);
        objEntity.MoveUnit(unitList[id].entitySetting, sf::Vector2f(unitList[id].unitProperties.posX, unitList[id].unitProperties.posY));
        emptyUnitListPos.pop_back();

        return id;
    }
//Add new position to vector
    else
    {
        unitList.push_back(objUnit);
        const int id = unitList.size()-1;
        unitList[id].isInUse = true;//This is set with the new object passed in anyway
        objEntity.AddUnitEntity(unitList[id].entitySetting);
        objEntity.MoveUnit(unitList[id].entitySetting, sf::Vector2f(unitList[id].unitProperties.posX, unitList[id].unitProperties.posY));
        return id;
    }
    return -1;
}

The error when compiling

1>C:\Program Files\Microsoft Visual Studio 11.0\VC\include\xmemory0(606): error C2248: 'std::unique_ptr<_Ty>::unique_ptr' : cannot access private member declared in class 'std::unique_ptr<_Ty>'

1>          with

1>          [

1>              _Ty=Item

1>          ]

1>          C:\Program Files\Microsoft Visual Studio 11.0\VC\include\memory(1447) : see declaration of 'std::unique_ptr<_Ty>::unique_ptr'

1>          with

1>          [

1>              _Ty=Item

1>          ]

1>          C:\Program Files\Microsoft Visual Studio 11.0\VC\include\xmemory0(605) : while compiling class template member function 'void std::allocator<_Ty>::construct(_Ty *,const _Ty &)'

1>          with

1>          [

1>              _Ty=std::unique_ptr<Item>

1>          ]

1>          C:\Program Files\Microsoft Visual Studio 11.0\VC\include\xmemory0(751) : see reference to function template instantiation 'void std::allocator<_Ty>::construct(_Ty *,const _Ty &)' being compiled

1>          with

1>          [

1>              _Ty=std::unique_ptr<Item>

1>          ]

1>          C:\Program Files\Microsoft Visual Studio 11.0\VC\include\type_traits(743) : see reference to class template instantiation 'std::allocator<_Ty>' being compiled

1>          with

1>          [

1>              _Ty=std::unique_ptr<Item>

1>          ]

1>          C:\Program Files\Microsoft Visual Studio 11.0\VC\include\vector(655) : see reference to class template instantiation 'std::is_empty<_Ty>' being compiled

1>          with

1>          [

1>              _Ty=std::allocator<std::unique_ptr<Item>>

1>          ]

1>          c:\c++\therpg\therpg\Inventory.h(53) : see reference to class template instantiation 'std::vector<_Ty>' being compiled

1>          with

1>          [

1>              _Ty=std::unique_ptr<Item>

1>          ]

Problem with multyple function with same name but different parameters and i get errors

04 April 2014 - 05:34 AM

Hello.

AFAIK this should work:

If you know why i am getting this, please help!

//HPP
void AddSpecialEffect(int posX, int posY, SpecialEffect & specialEffect, int * SpecialEffectVecID);
void AddSpecialEffect(int UnitVecID, SpecialEffect & specialEffect, int * SpecialEffectVecID);
 
//CPP
void SpecialEffectHolder::AddSpecialEffect(int PosX, int PosY, SpecialEffect & specialEffect, int * SpecialEffectVecID = 0)
{
    
}
void SpecialEffectHolder::AddSpecialEffect(int UnitVecID, SpecialEffect & specialEffect, int * SpecialEffectVecID = 0)
{
   
}

The compiler error

1>main.cpp(109): error C2664: 'void SpecialEffectHolder::AddSpecialEffect(int,SpecialEffect &,int *)' : cannot convert parameter 2 from 'int' to 'SpecialEffect &'
1>main.cpp(110): error C2664: 'void SpecialEffectHolder::AddSpecialEffect(int,SpecialEffect &,int *)' : cannot convert parameter 2 from 'int' to 'SpecialEffect &'
1>main.cpp(111): error C2664: 'void SpecialEffectHolder::AddSpecialEffect(int,SpecialEffect &,int *)' : cannot convert parameter 2 from 'int' to 'SpecialEffect &'
1>main.cpp(112): error C2664: 'void SpecialEffectHolder::AddSpecialEffect(int,SpecialEffect &,int *)' : cannot convert parameter 2 from 'int' to 'SpecialEffect &'
1>main.cpp(114): error C2661: 'SpecialEffectHolder::AddSpecialEffect' : no overloaded function takes 2 arguments

PARTNERS