vectors

Getting the same memory again and again

Hi In my program I am creating an object of a class in a loop and storing it in a vector. Then I print the address of the object and the member variable. After that I erase them . I see that every time I see the same address assigned to my object and the member variable which is a pointer. Can any one explain this behavior. #include ...

Numpy position and vector arrays - implement collision detection

I'm using point sprites in PyOpenGL with numpy and glDrawArrays. So I have two arrays, one for the points and one for the vectors. r = lambda: random.random() self.pts = numpy.zeros((2000,2), dtype=numpy.uint16) for pt in self.pts: pt[0] = 300*r() pt[1] = 200*r() self.vect...

Need examples on C++ vector usage

Given the C++ vector as below: vector<double> weight; weight.resize(128, 0); Can weight be used as: weight['A'] = 500.98; weight['P'] = 455.49; What does this mean? And how to use these values? Could anyone give me an example? thank you! ...

Fatal error from incrementing loop.

Currently, I'm trying to make a function that sorts a vector full of fighters in the function sortFighters in the Fighter.cpp file. It all seems to compile correctly; However, when it does run, I get a fatal error in one of the lines of the aformentioned .cpp file. I know exactly what the problem is, and put a comment there accordingly. ...

Vectors within classes: handeling copy constructor and destructor (C++)

Take a simple class with the "big 3" (constructor, copy constructor, destructor): #include <vector> using namespace std; //actually goes in the C file that links to this header file ... class planets(){ //stores mass and radii data for planets in a solar system. public: vector <double> mass; vector <double> radius; //...

Audio, AES CBC and IVs

Hello, I'm currently working on a voip project and have a question about the implementation of AES-CBC mode. I know that for instant messaging based on text message communication, it's important to generate an IV for every message to avoid possible guess of the first block if this one is redundant during the communication. But is it us...

c++ vectors causing break in my game

my works like this i shot airplanes and if the shot toughed an airplane it change there positions(airplane and the shot) than it will delete them. if i toughed an airplane the airplane position gets changed. than it gets deleted than my health reduces. well that works well expect that it breaks when i have about 2-4 airplanes left and i ...

How can I find the unit vector between a point and a line?

I have three known 3-Dimensional points: A, B, and C. Addtionally, I have a fourth point, X. X lies on vector AB such that vector CX is perpendicular to vector AB. So AB · CX = 0 How do I find the unit vector of CX? The use-case here is that I am constructing a (translated) rotational matrix, where the origin is A, the z-axis pass...

About C++ pointers

I am curious to how data is handled in the situation: chapterlist.clear(); cScene newscene; newscene.name = "Laura does something."; newscene.words = 432; newscene.pov = "Laura"; cChapter newchapter; newchapter.scenelist.push_back(newscene); chapterlist.push_back(newchapter); chapterlist is a cChapter vector. I am creating a new cSce...

c++ having strange problem

I have a function that creates and insert some numbers in a vector. if(Enemy2.dEnemy==true) { pt.y=4; pt.x=90; pt2.y=4; pt2.x=125; for(int i=0; i<6; i++) { Enemy2.vS1Enemy.push_back(pt); Enemy2.vS2Enemy.push_back(pt2); y-=70; pt.y=y; ...

How to adjust player sprite speed correctly? (Basically a math question?)

Background: I have a bird view's JavaScript game where the player controls a space ship by touching a circle -- e.g. touch to the left of the circle center, and the ship will move left, touch the top right and it will move to the top right and so on... the further away from the circle center of pseudo joystick, the more speed in that dir...

Calculate correct sprite direction image in bird's view game? (Math here might be speed vector to degrees angle?)

Background: I have 8 images for every sprite in my bird's view JavaScript game, representing top, top-right, right, right-bottom etc., depending on the player's space ship speed. Question: Given the values sprite.speed.x and sprite.speed.y (which could be something like 4 and -2.5, or 2 and 0 for instance), how do I get the correct angl...

Why use Float.floatToIntBits() in Java float comparisons?

In JBox2d, there exists the following code for Vec2.equals(): @Override public boolean equals(Object obj) { //automatically generated by Eclipse if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Vec2 other = (Vec2) obj; if (Float.float...

How to find common elements from multiple vectors?

Can anyone tell me how to find the common elements from multiple vectors? a <- c(1,3,5,7,9) b <- c(3,6,8,9,10) c <- c(2,3,4,5,7,9) I want to get the common elements from the above vectors (ex: 3 and 9) ...

How to cbind or rbind different lengths vectors without repeating the elements of the shorter vectors?

cbind(1:2, 1:10) [,1] [,2] [1,] 1 1 [2,] 2 2 [3,] 1 3 [4,] 2 4 [5,] 1 5 [6,] 2 6 [7,] 1 7 [8,] 2 8 [9,] 1 9 [10,] 2 10 I want an output like below [,1] [,2] [1,] 1 1 [2,] 2 2 [3,] 3 [4,] 4 [5,] 5 [6,] 6 [7...

How to wrap a c++ vector of vector with SWIG.

Hi, I'm using SWIG to wrap C++ code to Python code. I'm trying to wrap a vector of vectors. The method is: std::vector<std::vector<MyClass*>*> GetMyClassVectorOfVectors(); I'm able to wrap the first vector without adding lines to the file "MyAplication.i": The method is std::vector<MyClass*> GetMyClassVector(); And this is working...

Wrap std::vector of std::vectors, C++ SWIG Python

I want to wrap a C++ vector of vectors to Python code by using SWIG. Is it possible to wrap this type of vector of vectors? std::vector<std::vector<MyClass*>>; In the interface file MyApplication.i I added these lines: %include "std_vector.i" %{ #include <vector> %} namespace std { %template(VectorOfStructVector) vector<vecto...

Terminating multi-line user input?

Hey all, having a bit of a problem with a recent project. The goal here is to be able to input several lines of text containing a date in mm/dd/yyyy format followed by a whitespace and then a description of the event. I've accomplished actually allowing for multiple lines of text input (I think), but now I'm not exactly sure how to stop ...

How to use a matrix to rotate the reference system of a vector relatively to another?

Real-life case (helps understand the question) I am building a device that can freely rotate around all its axis (x, y, z) and is equipped with: an accelerometer (A) that gives me a vector pointing to the centre of the Earth (Va) a 3D magnetometer (M) that gives me the direction of the magnetic field of the Earth (Vm) The two vector...

signed distance between plane and point

Hey guys, I have been looking all over google and cannot find a consistent method for finding the signed distance between a point and a plane. My planes are defined by a point and a normal. Here is what I have. JGCameraPlane p; // Calculate D part of plane equation float d = -dotProduct(p.normal, p.point); What do I do from here? Did ...