C++ :: Quaternion For Rotating Vectors
Dec 28, 2013
I try to use quaternion to rotate one(and later more!) 3d-vectors in a general manner.
i read in wikipedia, that the general calculation goes with:
vector_rot = quaternion * vector * quaternion_compl.conj.
I used the class of irrlicht [URL] .... to do the calculations.
there is no premade function in this class to rotate vectors through this quaternions, so i just tried to it this way:
irr::core::vector3df v1(1,0,0);
irr::core::quaternion a1(2,3,4,6);
a1.normalize();
irr::core::vector3df result2(a1.X*v1.X*(-a1.X),a1.Y*v1.Y*(- a1.Y),a1.Z*v1.Z*(-a1.Z));
result2 should then be the rotated vector, but it does not work. i dont know how to explicitely write down the rotation specification in this topic.
View 7 Replies
ADVERTISEMENT
Jul 7, 2014
So I've got a sensor (contains a gyroscope, accelerometer, and magnetometer) that outputs quaternion data. I'm looking to take that data and use it to display the rotation of my sensor in the form of some object on the screen. I've seen instances where programs use a cube, but I'm hoping to figure out a way to have a little more control over what the object I'm rendering is.
how to get started? Are there any software packages that might be able to accomplish this?
View 1 Replies
View Related
Jun 10, 2014
Just bought a new ST Micro iNEMO-M1 system, and am looking to have my code visually show me the rotation information. I've got a working C++ code which actively acquires data from the sensor, and I'm looking to extend that into some visual interface which will show me on-screen the position of the sensor.
I figure using rotation information in the form of quaternion data is the most useful (want to avoid the gimbal lock problems associated with Roll/Pitch/Yaw).
What would be the best method to visualize the rotation of my sensor in real-time?
View 2 Replies
View Related
Aug 16, 2012
I have a 3d Point in space. From this point I have vertices defind by(scale). I have a Quaternion representing the rotation of the object (lets say a block). So...
(1) I know the point in local and world space and can translate.
(2) I know the scale of the object and it's starting vertices intersections at zero rotation.
(3) I have the quaternion which represents the 3d rotation and can translate that to degrees and Eulers.
How do i find the exact points of the vertices after the rotation. (what I'm attempting to do is plot points from vertice to vertice all along the sides/top/bottom of the object.)I have looked at Matrix4 transformations and Quaternions and still do not understand how to find the vertices after rotation.
View 8 Replies
View Related
Apr 21, 2014
I wrote a script that generates n random pixel positions and draws them to the screen. Works well. Now i tried to rotate them. Rotating does work too. But it does not work as i planned it.
paramters 'angle' and 'timestep' work somehow, but not as they should do. the function 'move' is supposed to rotate the pixelfield 'angle' degrees in a given direction, addicted to the 'timestep' parameter. 'timestep' is needed time for drawing in one single game loop.
angle_step = timestep * angle
// x
ppdPoint[i]->x =
pRotationPoint->x + cos(angel_step) * (ppdPoint[i]->x - pRotationPoint->x) - sin(angel_step) * (ppdPoint[i]->y - pRotationPoint->y);
// y
ppdPoint[i]->y =
pRotationPoint->y + sin(angel_step) * (ppdPoint[i]->x - pRotationPoint->x) + cos(angel_step) * (ppdPoint[i]->y - pRotationPoint->y);
rotation point is the middle of the screen. when i set angle to 10 it should rotate 10 degrees / second. Instead it's rotating very very fast and all stars are moving nearer to the center of the screen, so after x rounds there is just 1 pixel left in the middle of the screen. there is a kind of gravition.I'm working with SDL2. What I did find out:
FPS is <= 60, 'cause of the 'SDL_RENDERER_PRESENTVSYNC' flag. When i skip that flag, for any reason the 'gravition' would take more time. FPS is <= 1400 then, 'though i got a natural game loop (i hope):
while(pBuild->getExecuteFlag())
{
pBuild->draw();
pBuild->update(time_dif, pTimeWindow->TimeStampB);
time_dif = (pTimeWindow->TimeStampB - pTimeWindow->TimeStampA);
time_dif *= 0.001;
pTimeWindow->TimeStampA = pTimeWindow->TimeStampB;
pTimeWindow->TimeStampB = SDL_GetTicks();
pBuild->count_fps(pTimeWindow->TimeStampB);
}
So maybe (timestep * angle) isn't the right way?
View 13 Replies
View Related
Aug 30, 2013
Any algorithm or function to rotate a displayed circle. To turn it 360 degrees like a car-tire. (It's needed to turn a turn-table in a model-railrod control program) .....
View 14 Replies
View Related
Jun 9, 2013
Since SDL doesn't have it's own function for rotating images and I'm tired of storing multiple angles of the same sprite in a file, I created my own function for doing so:
//XY Class
class XY {
public:
XY(){}
XY(float x, float y);
[Code] ....
The problem is while Spin does spin the surface correctly, some pixels are rotated to the same new position so gaps appear in the returned surface. I need a way of filling in the gaps so the returned image looks better. A link to a program I made that uses this function is below so you can see the problem that I'm talking about. [URL] ....
I currently use SDL 1.2. Could my problem be fixed if I used 2.0? For example, does SDL 2.0 have a built in function for rotating surfaces?
View 3 Replies
View Related
Feb 3, 2013
I have a problem with rotating an array and assigning it to different variables. This is wat i have done.
Code:
#include<stdio.h>#include<stdlib.h>
#include<conio.h>
#include<math.h>
int n[16],a[16],n1[16],n2[16],n3[16],n4[16],n5[16],n6[16],n7[16],n8[16],n9[16],n10[16],n11[16],n12[16],n13[16],n14[16],n15[16],n16[16], c=0;
int x[16],i,j,k;
int rotate();
[code]....
View 4 Replies
View Related
Mar 19, 2014
I create a list of vectors (a vector of n vectors of m elements).
std::vector <std::vector <int> > vsFA (n, std::vector<int>(n));
How I assign values? I try below, but not worked
void armazenaFA( std::vector <int> &vFA) // this function only knows about vFA
{ vsFA[n] [m]= simTime().dbl();
OR
vsFA[n].push_back(simTime().dbl());
}
View 1 Replies
View Related
Sep 19, 2014
This is probably a very basic question, but I need to create two vectors and then loop through the vectors and output each pair that is found.
The user will input min1 and max1 with step1 for the first vector and min2 and max2 and step2 for the second vector. Then the loops will go through and return the combinations will return each pair of the two vectors.
So if I input min1=1 and max1=10 and step1=1 and same for vector two the return would be:
[1,1]
[1,2]
.
.
.
[10,10]
This is for part of a homework assignment, but I can't continue on the assignment without first getting this simple part to work.
View 1 Replies
View Related
Mar 27, 2013
I want to add 2 vectors to print out so that there on the same line. What I am trying to make is an inventory system that will use 2 vectors to keep the pounds of the item and list the 2 vectors on one line.
(I am using Microsoft Visual C++ 2010 Express)
Like this:
0. empty 0
1. empty 0
2. empty 0
etc...
Right now it looks like this:
0. empty
0. 0
The code:
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cmath>
using namespace std;
int main() {
vector<string> inv;
[Code] ....
View 14 Replies
View Related
Apr 19, 2012
I have a vector I want to add book titles to, then i want to print my updated vector. This is best I have come up with but the program fails at the getline line. why?
string book;
cout << "Enter book to add: "<< endl;
getline(cin, book);
books.push_back(book);
for(int i = 0; i < books.size(); ++i) {
cout << i+1 << ". " << books[i] << endl;
}
View 1 Replies
View Related
Feb 20, 2014
My question is not in c++ programing , but because my aim is to make code that calculate the three angles between two vector i ask my question here
So as the title i have three point that create two vector and I want to get the angles in x,y and z of the point2
I used crosproduct that give me one angle without axe , I don't know in which axe this angle
My aim is the three angles for the 3 axes ....
View 7 Replies
View Related
Mar 25, 2014
I can't figure out the error in this code; it compiles but returns rubbish.
serge
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
[Code] ......
View 7 Replies
View Related
Apr 19, 2013
I'm trying to make it like a game. You would fire your gun, then have the option of reloading. If you run out of ammo and try to fire...it will automatically come out of your cache. Anyone who played a 3rd or first person shooter knows what I mean. I thought vectors would be the best course of actions since they can remove and add elements with ease. One of the many problems I have is subtracting the Hand Guns current ammo (size) from its maximum (capacity) to see how much to A. push_back into the clip and B. pop_back out of the cache. Can size() and capacity even be subtracted? Here's the code with what I believe to be all the possibilities.
#include<iostream>
#include<vector>
using namespace std;
int main(int argc,char** argv) {
vector<int> HG_cache (36,1);
vector<int> HG_clip (12,1);
char user_input;
[code]....
View 1 Replies
View Related
May 19, 2013
The following code works perfectly with "normal" C++
#include <iostream>
#include <vector>
int main() {
std::vector <std::string> hello {
[Code] ....
This prints "HELLO" on the screen. A function a bit more like NCurses is:
for (std::vector <std::string>::const_iterator it = hello.begin(); it != hello.end(); it++) {
std::string temp = *it;
std::cout << temp.c_str() << std::endl;
}
This still works with "normal" C++. Now, how do I get this working with NCurses? I tried
#include <curses.h>
#include <string>
#include <vector>
int main() {
initscr();
[Code] ....
But this just gives me an empty screen.
View 2 Replies
View Related
Mar 8, 2013
This is possibly more of an algorithm question rather than c++ related.Suppose I have two vectors:
std::vector<double> first = {1.0,2.01,3.05,4.05};
std::vector<double> second = {1,2,3,3,4}; // very similar except no decimals and a second "3"
And now I want an algorithm that will tell me how similar these two vectors are. That is, I want to know how much of first is similar to second.
View 6 Replies
View Related
Jul 31, 2013
I am trying to use push back in a 2D vector but I don't know how to. This is what I have:
vector <vector <BigInt> > matr;
for (BigInt i=0;i<rij;i++) {
for (BigInt j=0;j<kolom-1;j++) {
matr.push_back().push_back((i+1)^(pow-j));
}
}
I quickly invented something but that doesn't work obviously. it should be equivalent to this: (the only problem in the code below is that those indexes don't exist yet that's why I need push_back())
for (BigInt i=0;i<rij;i++) {
for (BigInt j=0;j<kolom-1;j++) {
matr[int(i)][int(j)]=(i+1)^(pow-j);
}
}
View 2 Replies
View Related
Nov 6, 2013
I my code i have a base struct ...
Then others structs made ...
struct base{};
struct a1 : base {
int a;
int b;
[Code] ....
Now i must deposit all these containers(maybe & of containers) in another vector...
How i can do that? Can i write
vector<vector<base*> > all;
all.push_back(&v1);
all.push_back(&v2);
View 14 Replies
View Related
Dec 9, 2013
I have a vector of vectors declared as:
vector<vector<int>> v;
My program works fine with a small number of insertions to v. However, with a huge number of insertions my program stops working without telling me the reason... I guess that vectors might not grow after a certain size (im not sure)
1. What is the maximum size that a vector of vectors can grow?
2. I'm using Microsoft visual studio 2012, Is their anything I can do with the settings to increase the size of my vector? something beyond 1000000 rows?
View 6 Replies
View Related
Sep 28, 2013
I've seen code examples for assigning 2 dimensional vectors, but I haven't seen code for assigning more than that. I tried to create a 3 dimensional vector, and the only code the IDE didn't complain about was
int x = 2;
int y = 2;
int z = 2;
vector < vector < vector <string> > >stringvec;
stringvec.assign(x, vector <string>(y), vector <string>(z));
Would this be the correct way of producting a vector[2][2][2]?
View 5 Replies
View Related
Sep 4, 2014
I have a doubt and I have two vectors to a function.
A vector is (int *, const int) and the other is (string *, const int) and want to spend the two vectors and unite in a single function
A vector is passed to a function, but spending two vectors and join I cannot find the turn.
try (int *, const int, string *, const int)
But only understands the former as I do
View 1 Replies
View Related
Oct 13, 2014
I have a CSV file that is formatted in the following way. The top row contains headers and the data is below. I have opened the file (sec2011) in Numbers on Mac and saved it as a csv. I would like to read each of the columns into a vector, but I can not get the code to even open the file.
secid,date,low,high,close,volume,return,cfadj,open,cfret,shrout
101310,03JAN2011,181.21,186,184.22,5331413,0.023444,12,181.37,12,448837
101310,04JAN2011,183.78,187.6995,185.01,5033144,0.004288,12,186.15,12,448837
ifstream infile("sec2011.csv");
if (!infile) {
cerr << "Couldn't open file!"<<endl;
return 1;
This code always returns the Couldn't open File text.
What am I doing wrong. I know the above code doesn't put the data into vectors, but I can't even get the file to read.
View 2 Replies
View Related
Jan 15, 2013
I'm trying to solve Project Euler 16 where you have to calculate 2^1000. SO I made a program that would solve multiplying a number b a single digit factor through manual multiplication in a vector, just to test things out.
The problem is when I take things out of main and try to make a separate function, the original number is never multiplied.
Here's my code with functions...
/*Using vectors manually to multiply a number to a positive power.*/
#include <iostream>
#include <vector>
using namespace std;
void print_vector(const vector<int>& v);
[code]....
Here is the other code, not using functions but even if I use an extra for loop to multiply by the same factor several times, it still does the same thing.
/*Using vectors manually to multiply a number by two (or any single digit factor).*/
#include <iostream>
#include <vector>
using namespace std;
void print_vector(const vector<int>& v);
[code]....
View 5 Replies
View Related
Jun 4, 2013
this time I have an ACTUAL polymorphic problem.
void func(std::vector< BaseClass* > A){}
std::vector< SubClass* > B;
func(B); //Compile error C2664
I get an error like so:
void func(std::vector< BaseClass* > *A){}
std::vector< SubClass* > B;
func(&B); //same error
The error is summarized here:[URL]
View 12 Replies
View Related
Apr 30, 2013
How would you search through the a list of vectors? I have a upper case letter at the start of the lists and corresponding lower case letters in vectors how would I search through it to see how many times the corresponding lower case letter was repeated?
View 1 Replies
View Related