vector

Quaternion Cameras and projectile vectors

In our software we have a camera based on mouse movement, and a quarternion at its heart. We want to fire projectiles from this position, which we can do, however we want to use the camera to aim. The projectile takes a vector which it will add to its position each game frame. How do we acquire such a vector from a given camera/quatern...

How do I simplify this templated vector initializer loop using lambdas or STL transform?

How do I simplify this templated vector initializer loop using lambdas or some kind of STL transform? template<typename T> template<typename... Args> void InitToRandomValues(vector<T>* retval, int n, RNG& rng, Args const&... args) { retval->resize(n); for (auto it = retval->begin(); it != retval->end(); ++it) { typename ...

How to std::find using a Compare object?

I am confused about the interface of std::find. Why doesn't it take a Compare object that tells it how to compare two objects? If I could pass a Compare object I could make the following code work, where I would like to compare by value, instead of just comparing the pointer values directly: typedef std::vector<std::string*> Vec; Vec...

C++ containers on classes, returning pointers

Hello, I'm having some trouble to find the best way to accomplish what I have in mind due to my inexperience. I have a class where I need to a vector of objects. So my first question will be: is there any problem having this: vector< AnyType > container* and then on the constructor initialize it with new (and deleting it on the destruc...

C++ Map of Vector of Structs?

So here's a snippet of my code: struct dv_nexthop_cost_pair { unsigned short nexthop; unsigned int cost; }; map<unsigned short, vector<struct dv_nexthop_cost_pair> > dv; I'm getting the following compiler error: error: ISO C++ forbids declaration of `map' with no type What's the proper way to declare thi...

Is there a decent vector / spline library for php?

Does anyone know of the best way to render clean vectors into a php image and then serve it as a jpeg/png? Specifically I want to draw lines, polygons and splines which are anti-aliased and then serve them up as jpegs. Preferably also with an alpha option when rendering. What would be spectacular is a php library with a similar API to ...

Perturb vector by some angle

Hello: I have a unit vector in 3D space whose direction I wish to perturb by some angle within the range 0 to theta, with the position of the vector remaining the same. What is a way I can accomplish this? Thanks. EDIT: After thinking about the way I posed the question, it seems to be a bit too general. I'll attempt to make it more sp...

std::vector capacity after copying

Does vector::operator= change vector capacity? If so, how? Does vector's copy constructor copy capacity? I looked through documentation but could not find a specific answer. Is it implementation dependent? ...

How do I initialize the vector I have defined in my header file?

I have the following in my Puzzle.h class Puzzle { private: vector<int> puzzle; public: Puzzle() : puzzle (16) {} bool isSolved(); void shuffle(vector<int>& ); }; and then my Puzzle.cpp looks like: Puzzle::Puzzle() { // Initialize the puzzle (0,1,2,3,...,14,15) for(int i = 0; i <= puzzl...

Why is shrink_to_fit non-binding?

The C++0x FCD states in 23.3.6.2 vector capacity: void shrink_to_fit(); Remarks: shrink_to_fit is a non-binding request to reduce capacity() to size(). [Note: The request is non-binding to allow latitude for implementation-specific optimizations. end note] What optimizations are intended to be allowed? ...

Angle between two 2d vectors, diff between two methods?

Hey all. I've got this code snippet, and I'm wondering why the results of the first method differ from the results of the second method, given the same input? public double AngleBetween_1(vector a, vector b) { var dotProd = a.Dot(b); var lenProd = a.Len*b.Len; var divOperation = dotProd/lenProd; return Math.Acos(divOperation) *...

How to interpret situations where Math.Acos() reports invalid input?

Hey all. I'm computing the angle between two vectors, and sometimes Math.Acos() returns NaN when it's input is out of bounds (-1 > input && input > 1) for a cosine. What does that mean, exactly? Would someone be able to explain what's happening? Any help is appreciated! Here's my method: public double AngleBetween(vector b) { ...

Is there a way to specify the dimensions of a nested STL vector C++?

I know vectors can be constructed to a predefined size vector<int> foo(4); But is there a way to specify the dimensions of nested vectors? vector< vector<int> > bar(4); Lets say I wanted a vector of size 4 containing vector's of size 4... like a 4x4 multidimensional array of ints? ...

Finding character in String in Vector.

Judging from the title, I kinda did my program in a fairly complicated way. BUT! I might as well ask anyway xD This is a simple program I did in response to question 3-3 of Accelerated C++, which is an awesome book in my opinion. I created a vector: vector<string> countEm; That accepts all valid strings. Therefore, I have a vector ...

vector::erase with pointer member

I am manipulating vectors of objects defined as follow: class Hyp{ public: int x; int y; double wFactor; double hFactor; char shapeNum; double* visibleShape; int xmin, xmax, ymin, ymax; Hyp(int xx, int yy, double ww, double hh, char s): x(xx), y(yy), wFactor(ww), hFactor(hh), shapeNum(s) {visibleShape=0;shapeNum=-1;}; //Copy constru...

Boost::Container::Vector with Enum Template Argument - Not Legal Base Class

Hi, I'm using Visual Studio 2008 with the Boost v1.42.0 library. If I use an enum as the template argument, I get a compile error when adding a value using push_back(). The compiler error is: 'T': is not a legal base class and the location of the error is move.hpp line 79. #include <boost/interprocess/containers/vector.hpp> class Te...

Vector Troubles in C++

I am currently working on a project that deals with a vector of objects of a People class. The program compiles and runs just fine, but when I use the debugger it dies when trying to do anything with the PersonWrangler object. I currently have 3 different classes, one for the person, a personwrangler which handles all of the people colle...

Finding if all elements in a vector<string> are in a string

I have a vector and I need to see if all the strings in that vector are substrings of another given string. eg vector<string> v; v.push_back("str1"); v.push_back("str2"); string s1 = "str1, str2, str3"; string s2 = "str1, str3"; Is there a way to get true from s1 and false from s2 without looping over the vector? Also, note that due...

C# Vector maths questions

Im working in a screen coordinate space that is different to that of the classical X/Y coordinate space, where my Y direction goes down in the positive instead of up. Im also trying to figure out how to make a Circle on my screen always face away from the center point of the screen. If the center point of my screen is at x(200) y(300) ...

Rare PyCairo antialias getting directly the surface data

After create a Pycairo context and surface (ImageSurface) I get a diferent export results if I get directly from surface buffer surface.get_data() or from PNG export method surface.write_to_png() The context antialias flag is obviously the same and, yes, the get_data method result has antialiasing, but with much poorer quality. Wh...