1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

STL: Using vector to manage 3D vectors (3D games)

Discussion in 'C' started by david_BS, May 20, 2012.

  1. david_BS

    david_BS New Member

    Joined:
    Apr 5, 2012
    Messages:
    16
    Likes Received:
    3
    Trophy Points:
    0
    Credits: BS, OGC

    A small demostration of the usage of std::vector to create a simple management system to manage 3D vectors. I used this in a game hack for CS

    Code:
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //
    //
    // UTN FRGP TSP
    // BS
    // mail: david_bs@live.com
    // web: Etalking.Com.Ar
    // 2012
    //
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    #include <windows.h>
    #include <stdio.h>
    #include <fstream.h>
    #include <vector>
    
    using namespace std;
    
    struct vec
    {
    	float h;
    	float f;
    	float r;
    };
    
    #define VEC_INDEX_MAX 32
    vector<vec> Vecs[VEC_INDEX_MAX];
    
    #define VECS 6
    
    Functions to add, list and erase, as in every management system
    Code:
    void func_vec_add(int index, float x, float y, float z)
    {
    	vec v;
    	v.h = z;
    	v.f = x;
    	v.r = y;	 *
    	if(index<=VECS){
    		Vecs[index].push_back(v);
    	}
    }
    
    void func_vec_clear(int index)
    {
     * *if(index == -1){
     * * * for(int i=0;i<=VECS;i++)
    		 * Vecs[i].clear();
     * *}
    	else if(index>=0&&index<=VECS){
     * * * * * *Vecs[index].clear();
     * *}
    }
    
    void func_vec_list(int index)
    {
    	cout << "\n";
    
    	if(index == -1){
    
    		int cantidad=0;
    
    		for(int i=0;i<=VECS;i++)
    		for(vector<vec>::iterator si = Vecs[i].begin(); si != Vecs[i].end();++si)
    		{
    			 cantidad++;
    			 printf("Height: %f Forward: %f Right: %f\n",si->h,si->f,si->r);
    		}
    
    		if(cantidad==0)
    			cout << "There are no elements !" << endl;
    	}
    
    	else
    	{
    		if(index<=VECS){
    		 * for(vector<vec>::iterator si = Vecs[index].begin(); si != Vecs[index].end();++si)
    		 * {
    				printf("Height: %f Forward: %f Right: %f\n",si->h,si->f,si->r);
    		 * }
    		}
    	}
    }
    
    Main function, used for testing purposes
    Code:
    int main(){
    
    	func_vec_add(0, 100, 200, 0.61f);
    	func_vec_add(1, 100, 200, 0.98f);
    	func_vec_add(2, 100, 200, 0.59f);
    	func_vec_add(3, 100, 200, 0.15f);
    	func_vec_add(4, 100, 200, 0.00f);
     * * * *func_vec_add(5, 100, 500, 1.00f);
    	func_vec_add(6, 100, 900, 2.00f);
    
    	//func_vec_list(0);
    	func_vec_list(-1);
    
    	func_vec_clear(-1);
    
    	func_vec_list(-1);
    
    	cin.get();
    	return 0;
    }
    
     

Share This Page