Jump to content

  • Log In with Google      Sign In   
  • Create Account

xinfinite33

Member Since 12 Oct 2012
Offline Last Active Dec 04 2014 11:47 PM

Topics I've Started

Custom window GUI system

07 May 2013 - 05:04 AM

hello everyone! I made a simple game and I came across a problem, editing levels. I made my game so that it stores the level data in text files, so levels have to be built manually by directly editing the text file, this was rather tedious so i started working on a level editor and I'm having one problem, the GUI. I would like to  create a GUI system that can create windows with buttons, sliders, check-boxes, etc. and I've been trying out different methods but its harder than I thought it would be. I don't want the GUI code to be platform specific so I chose not to use third party libraries. can someone give me an idea of how a GUI system should be structured or point me to some articles/tutorials about the subject? any help at all would be greatly appreciated.


smoothed lines

13 April 2013 - 01:18 AM

ive been trying to find a way to take a set of points and draw a "smoothed" line that passes through all the points. i tried bezier curves and they do a good job at smoothing the line, but the line doesn't pass through the points,it passes between them. so is there a simple algorithm i can use so that the line will actually pass though all of the points but at the same time make it so that the line is smooth and not rigid?


smart pointer trouble

24 December 2012 - 07:59 AM

I've been trying to work with smart pointers pointers and i'm having trouble.  if you have an object that has a pointer to another object, for example, my object stores a pointer to the closest object relative to itself, this makes a pointer cycle ,object 2 pointing to object 1 and object 1 pointing to object 2. how can i make it so that if an object gets deleted, all pointers pointing to it get set to NULL? iv'e tried this with shared pointers and auto pointers but i cant get anything to work how i want it. here's some code for a better understanding.

#include <iostream>
#include <memory>
using namespace std;

class person
{
    public:

        int value;
        shared_ptr<person> buddy;
        static int Count;

        person(int v)
        {
            this->value=v;
            Count++;
        }

        person(const person & other )
        {
            this->value=other.value;
            this->buddy=other.buddy;
        }

        ~person()
        {
            Count--;
        }



};

int person::Count=0;

int main()
{
        shared_ptr<person> test(new person(5));
        shared_ptr<person> test2(new person(37));
        test->buddy=test2;
        test2->buddy=test;
        cout<<(test->buddy)->value<<endl;
        cout<<(test2->buddy)->value<<endl;
        test=NULL;                             //destroy the first person and set all pointers pointing to it to NULL here. how do i do that?
        if(test2->buddy==NULL)
        {
            cout<<"null pointer detected. do nothing";
        }
        else
        {
            cout<<"person detected, print value: "<<test2->buddy->value;     //this shouldnt happen, it should detect null because test 1 was destroyed
        }

return 0;
}

 

 

 


static std::deque inside of template class

22 December 2012 - 06:13 AM

im having a problem with a static deque inside of one of my classes. i know that you have to initialize static members of a class before you can use them but i cant figure out how to initialize a static deque inside of a template class. a little help please?

 

#include <iostream>
#include <deque>

using namespace std;



template <typename T>
class jar
{
    public:
    T * value;
    static int jars;
    static deque<jar*> jarlist;

    template<typename S>
    jar(S obj) //constructor
    {
        this->value= &obj;
        jars++;
        jarlist.push_back(this);
    }

    void destroy() //destroys a jar
    {
        {
            typename deque<jar*>::iterator iter;

            for (iter=jarlist.begin();iter!=jarlist.end();iter++)
            {
                if(*iter==this)
                {
                    delete (*iter);
                    jarlist.erase(iter);
                }
            }
            jars--;
        }
    }

};

template<typename T> int jar<T>::jars=0;
template<typename T> deque<jar*> jar<T>::jarlist; // <---------------------PROBLEM HERE---------------

int main()
{
    int integer=3;
    jar A(integer);

    cout<<*(jar::jarlist.front())->value);

    return 0;
}

 

any help would be greatly appreciated


simple 8 way direction finding algorithm?

30 November 2012 - 11:15 AM

hi guys. Well the problem I'm having is that I have been trying to create a simple function that takes in 2 points and determines the direction from one point to another then displays the direction as N,NE,E,SE,S,SW,W,NW Like a compass. I found a very simple way to do this for 4 directions by subtracting point 2's coordinates from point 1's coordinates. then I get the absolute value of the x distance and the y distance and determine which axis's distance is greater. if the Y distance is greater, then point2 is either North(negative) or South(positive) of point1, and If the X distance is greater, then point2 is either East(positive) or West(negative) of point1. This method is very fast, But as you see this only provides 4 directions. Is there a simple trick similar to this one that yields 8 directions instead of 4? I know I could just go the angular route and divide 360 by 8, then find the angle of point A to point B and see which range it lies in, but i'm trying to find a simpler solution that doesn't use division or other expensive operations, just for the sake of tiny optimizations lol. Any ideas?

PARTNERS