小编aar*_*mar的帖子

在Android 2.1中使用getRotationMatrix和getOrientation

我长期以来一直遇到这个问题.此代码应输出加速度计的dx,dy,dz以及dx的运行总和.它还应输出方位角,俯仰和滚动.

我已经使用了这里给出的信息,但无济于事.

此代码无法正确输出音高,方位角或滚动.它分别为最后三个文本视图输出0.0,-0.0,-0.0.

switch (event.sensor.getType()) {
    case Sensor.TYPE_ACCELEROMETER:
        accelerometerValues = event.values.clone();
    case Sensor.TYPE_MAGNETIC_FIELD:
        geomagneticMatrix = event.values.clone();
        sensorReady = true;
        break;
    default:
        break;
}   

if (geomagneticMatrix != null && accelerometerValues != null && sensorReady) {
    sensorReady = false;

    float[] R = new float[16];
    float[] I = new float[16];

    SensorManager.getRotationMatrix(R, I, accelerometerValues, geomagneticMatrix);

    float[] actual_orientation = new float[3];
    SensorManager.getOrientation(R, actual_orientation);

    tvXCoordinate.setText(accelerometerValues[0] + "");
    tvYCoordinate.setText(accelerometerValues[1] + "");
    tvZCoordinate.setText(accelerometerValues[2] + "");

    floatXTotal += accelerometerValues[0];
    tvXTotal.setText(floatXTotal + "");

    tvAzimuth.setText(actual_orientation[0] + "");
    tvPitch.setText(actual_orientation[1] + ""); …
Run Code Online (Sandbox Code Playgroud)

java events android matrix sensor

8
推荐指数
1
解决办法
2万
查看次数

奇怪的stdout行为

我目前正在用C++编写一个套接字程序,由于某种原因,我在尝试写入控制台(一项必需的任务)时遇到了非常奇怪的行为.

cout << themsg[0] << themsg[1] << endl;
cout << "Phase 3: Supernode sent the message " << themsg[0] << " on dynamic port number " << themsg[1] << endl;
Run Code Online (Sandbox Code Playgroud)

themsg [0]是字符串"User#2:Dick是什么?"

themsg [1]是字符串"39416"

第一行应写"用户#2:怎么了迪克?" 到控制台,然后是"39416".

第二行应打印"第3阶段:超级节点发送消息用户#2:怎么了迪克?动态端口号39416"

控制台输出如下所示:

394162:What's up Dick?
on dynamic port number 39416essage User#2:What's up Dick?
Run Code Online (Sandbox Code Playgroud)

我知道themsg [0]和themsg [1]是正确的,因为我将它们的值写入文件进行验证.它肯定是一些奇怪的stdout问题.

对于第一行,出现themsg [1]的5个字符会覆盖themsg [0]的前五个字符.对于第二行,似乎忽略了cout的前两个参数,然后附加了一个消息片段.

如果有人可以提供帮助,我会非常感激.我尝试使用flush()但无济于事.我不确定输出缓冲区是如何工作的,所以我真的迷失了.

c++ buffer cout stdout std

1
推荐指数
1
解决办法
173
查看次数

C++套接字recv()系统调用返回-1

我目前在服务器和客户端之间传递消息时遇到问题.据我所知,我正在遵循Beej的套接字编程教程概述的套接字编程的最佳实践.

当我运行这两个进程时,recv()系统调用返回-1(错误),而不是接收的字节数.此外,当尝试输出buf时,有一堆gobbledygook字符.这是有道理的,因为错误.

我想知道是否有人可以引导我朝着正确的方向指导我为什么遇到recv()的问题?以下是相关的代码片段.

服务器:

struct sockaddr_storage their_addr;
socklen_t addr_size;
int sockfd, newfd, byte_count, status;
char buf[512];
struct addrinfo hints,  *res;

//  first,  load  up  address  structs  with  getaddrinfo():
memset(&hints,  0,  sizeof  hints);
hints.ai_family  =  PF_INET;
hints.ai_socktype  =  SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;

// get address info, print stuff if error
if((status = getaddrinfo("nunki.usc.edu",  "21957",  &hints,  &res)) !=0){
    fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(status));
    exit(1);
}

//  make  a  socket:
if((sockfd  =  socket(res->ai_family,  res->ai_socktype,  res->ai_protocol)) == -1){
    cout << …
Run Code Online (Sandbox Code Playgroud)

c++ sockets linux

0
推荐指数
1
解决办法
1749
查看次数

标签 统计

c++ ×2

android ×1

buffer ×1

cout ×1

events ×1

java ×1

linux ×1

matrix ×1

sensor ×1

sockets ×1

std ×1

stdout ×1