2直截了当的问题 [英] 2 straight forward Questions

查看:50
本文介绍了2直截了当的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正确,

1:是否有包含矩阵和复数的标准库。我需要找到一个3x3矩阵的特征值。


2:有没有办法从<获取指向数组开头的指针br />
存储在std向量中的数据。我在

时刻将一堆浮点数加载到一个向量中来存储openGL的顶点信息,但为了渲染它们,我需要

将一个指针传递给一个开头。数组到OpenGL,而不是向量。在

时刻,我只是将它们变成了另一个阵列,但这似乎有点浪费了:b / b
$ b vector< float>顶点;


//将数据复制到''顶点''


然后在渲染之前我必须:

float * pVertexArray = new float [vertices.size()];

for(int i = 0; i< vertices.size(); i ++)pVertexArray [i] = vertices [i];

但这看起来很傻!


谢谢Mike。

解决方案



" Michael" < SL *********** @ hotmail.com>在消息中写道

news:c7 ********** @ hercules.btinternet.com ...

Righty,

1:是否有包含矩阵和复数的标准库。
我需要找到3x3矩阵的特征值。


头文件中有复杂的数字< complex>


std :: complex< double> c(1.0,2.0);

std :: complex< double> d = c * c;





没有这样的矩阵。但是你有很多选择。你可以

写一个简单的类来完成你所需要的一切(我认为这是最好的)。或者

你可以使用矢量向量。你可以使用valarray。

2:有没有办法从
获取指向数组开头的指针存储在std向量中的数据。


是的。

我在
时刻将载荷加载到矢量中以存储openGL的顶点信息,但要渲染它们,我需要
将指向数组开头的指针传递给OpenGL,而不是向量。在
的那一刻,我只是将它们压缩成另一个阵列,但这似乎是浪费的


vector< float>顶点;

//将数据复制到''顶点''
然后在渲染之前我必须:
float * pVertexArray = new float [vertices.size( )];
for(int i = 0; i< vertices.size(); i ++)pVertexArray [i] = vertices [i];

但这看起来很傻!



对,就这样做


some_function(& vectices [0]);


john


Michael写道:

Righty,

1:是否有包含矩阵的标准库


不,但是有很多可用的第三方库,其中许多是开源的。试试Google。

和复数。


#include< complex>

我需要找到3x3矩阵的特征值。

2:有没有从存储在std向量中的
数据获取指向数组开头的方法。






" Michael" < SL *********** @ hotmail.com>在消息中写道

news:c7 ********** @ hercules.btinternet.com ...

Righty,

1:是否有包含矩阵和复数的标准库。我需要找到3x3矩阵的特征值。


有std :: complex类(#include< complex>)

没有类这样的矩阵,但你可以看看valarray。

2:有没有办法从存储在std向量中的
数据中获取指向数组开头的指针。我在
时刻将大量浮点数加载到向量中以存储openGL的顶点信息,但为了渲染它们,我需要将指向数组开头的指针传递给OpenGL,而不是向量。在
时刻,我只是将它们编成另一个阵列,但这似乎有点浪费:

vector< float>顶点;

//将数据复制到''顶点''
然后在渲染之前我必须:
float * pVertexArray = new float [vertices.size( )];
for(int i = 0; i< vertices.size(); i ++)pVertexArray [i] = vertices [i];




& vec [0]会给你指向第一个元素的指针。


-Sharad


Righty,
1: Is there a standard library that contain matrices and complex numbers. I
need to find eigen values of a 3x3 matrix.

2: Is there a way of getting the pointer to the start of an array from the
data stored in a std vector. I load loads of floats into a vector at the
moment to store vertex infomration for openGL, but to render them, I need to
pass a pointer to the beginning of the array to OpenGL, not a vector. At the
moment I''m just compying them into another array, but this seems like a bit
of a waste:

vector<float> vertices;

//Copy data into ''vertices''

Then before rendering I have to :
float* pVertexArray = new float[vertices.size()];
for(int i=0;i< vertices.size();i++) pVertexArray[i] = vertices[i];
But this seems silly!

Thanks Mike.

解决方案


"Michael" <sl***********@hotmail.com> wrote in message
news:c7**********@hercules.btinternet.com...

Righty,
1: Is there a standard library that contain matrices and complex numbers. I need to find eigen values of a 3x3 matrix.
There are complex numbers in the header file <complex>

std::complex<double> c(1.0, 2.0);
std::complex<double> d = c*c;

etc.

There are no matrices as such. But you have a lot of options. You could
write a simple class that does all you need (I think that would be best). Or
you could use a vector of vectors. Of you could use valarray.

2: Is there a way of getting the pointer to the start of an array from the data stored in a std vector.
Yes.
I load loads of floats into a vector at the
moment to store vertex infomration for openGL, but to render them, I need to pass a pointer to the beginning of the array to OpenGL, not a vector. At the moment I''m just compying them into another array, but this seems like a bit of a waste:

vector<float> vertices;

//Copy data into ''vertices''

Then before rendering I have to :
float* pVertexArray = new float[vertices.size()];
for(int i=0;i< vertices.size();i++) pVertexArray[i] = vertices[i];
But this seems silly!



Right, just do this

some_function(&vectices[0]);

john


Michael wrote:

Righty,
1: Is there a standard library that contain matrices
No, but there are plenty of third-party libraries available, many of
them open source. Try Google.
and complex numbers.
#include <complex>
I need to find eigen values of a 3x3 matrix.

2: Is there a way of getting the pointer to the start of an array from the
data stored in a std vector.



&v[0]; // Not sure the standard mandates this, but I think there''s a DR.



"Michael" <sl***********@hotmail.com> wrote in message
news:c7**********@hercules.btinternet.com...

Righty,
1: Is there a standard library that contain matrices and complex numbers. I
need to find eigen values of a 3x3 matrix.
There is std::complex class (#include <complex>)
No class as such for matrices but you could take a look at valarray.
2: Is there a way of getting the pointer to the start of an array from the
data stored in a std vector. I load loads of floats into a vector at the
moment to store vertex infomration for openGL, but to render them, I need to
pass a pointer to the beginning of the array to OpenGL, not a vector. At the
moment I''m just compying them into another array, but this seems like a bit
of a waste:

vector<float> vertices;

//Copy data into ''vertices''

Then before rendering I have to :
float* pVertexArray = new float[vertices.size()];
for(int i=0;i< vertices.size();i++) pVertexArray[i] = vertices[i];



&vec[0] will give you the pointer to the first element.

-Sharad


这篇关于2直截了当的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆