小编Rol*_*oós的帖子

函数指针作为参数

我尝试调用一个函数,该函数作为函数指针传递,没有参数,但我不能使它工作.

void *disconnectFunc;

void D::setDisconnectFunc(void (*func)){
    disconnectFunc = func;
}

void D::disconnected(){
    *disconnectFunc;
    connected = false;
}
Run Code Online (Sandbox Code Playgroud)

c++ pointers function-pointers function

52
推荐指数
3
解决办法
9万
查看次数

3d加速度计计算方向

我有3轴的加速度计值(通常只有重力包含介于-1.0和1.0之间的数据):

  float Rx;
  float Ry;
  float Rz;
Run Code Online (Sandbox Code Playgroud)

我做了躯体计算,然后我得到每个轴的角度.

  float R =  sqrt(pow(Rx,2)+pow(Ry,2)+pow(Rz,2));
  float Arx = acos(Rx/R)*180/M_PI;
  float Ary = acos(Ry/R)*180/M_PI;
  float Arz = acos(Rz/R)*180/M_PI;
Run Code Online (Sandbox Code Playgroud)

然后我在opengl中设置框角度的值

rquad = Arx;
yquad = Ary;
Run Code Online (Sandbox Code Playgroud)

哪个旋转我的盒子:

glRotatef(yquad,1.0f,0.0f,0.0f);
glRotatef(rquad,0.0f,1.0f,0.0f);
Run Code Online (Sandbox Code Playgroud)

它适用于半球.我想使用完整的球体,我知道我必须使用Arz值使其工作,但我不知道如何使用它进行此旋转.你可以帮帮我吗?

更新:最终答案在我的情况下:

  rquad = -atan2(Rx/R, Rz/R)*180/M_PI;
  yquad = -atan2(Ry/R, Rz/R)*180/M_PI;
Run Code Online (Sandbox Code Playgroud)

c opengl math

30
推荐指数
3
解决办法
4万
查看次数

OpenCV卡尔曼滤波器

我有三个陀螺仪值,俯仰,滚转和偏航.我想添加卡尔曼滤波器以获得更准确的值.我找到了opencv库,它实现了卡尔曼滤波器,但我无法理解它是如何工作的.

你能帮我一些帮助吗?我没有在互联网上找到任何相关主题.

我试着让它适用于一个轴.

const float A[] = { 1, 1, 0, 1 };
CvKalman* kalman;
CvMat* state = NULL;
CvMat* measurement;

void kalman_filter(float FoE_x, float prev_x)
{
    const CvMat* prediction = cvKalmanPredict( kalman, 0 );
    printf("KALMAN: %f %f %f\n" , prev_x, prediction->data.fl[0] , prediction->data.fl[1] );
    measurement->data.fl[0] = FoE_x;
    cvKalmanCorrect( kalman, measurement);
}
Run Code Online (Sandbox Code Playgroud)

在主要

kalman = cvCreateKalman( 2, 1, 0 );
state = cvCreateMat( 2, 1, CV_32FC1 );
measurement = cvCreateMat( 1, 1, CV_32FC1 );
cvSetIdentity( kalman->measurement_matrix,cvRealScalar(1) );
memcpy( kalman->transition_matrix->data.fl, A, …
Run Code Online (Sandbox Code Playgroud)

c c++ opencv kalman-filter

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

YouTube在IOS和Android上嵌入了API问题

最近几天,YouTube嵌入API出现了问题.问题是,当您使用官方API嵌入视频时,它只是不允许您访问API.当您尝试访问API时,您在日志(IOS)上收到错误消息,如果您尝试通过API播放视频,则视频会消失.如果您通过API加载它,但不使用API​​,则用户可以通过点击播放视频.

该问题在以下浏览器中仍然存在:

iPad和iPhone上的IOS 7 Safari IOS 7 iPad和iPhone上的Chrome Android 4 Chrome

(我的播放按钮使用API​​播放视频并产生错误)JSfiddle:http://jsfiddle.net/frdd8nvr/6/

错误信息:

Unable to post message to https://www.youtube.com. Recipient has origin http://fiddle.jshell.net.
postMessage[native code]:0
Jwww-widgetapi.js:26:357
Nwww-widgetapi.js:25
(anonymous function)[native code]:0
html5player.js:1201:97

Blocked a frame with origin "https://www.youtube.com" from accessing a frame with origin "http://jsfiddle.net".  The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "http". Protocols must match.
Run Code Online (Sandbox Code Playgroud)

一些调试信息:

我看到API在网站上创建iframe.src有时是http,有时是https.

http://www.youtube.com/embed/ZPy9VCovVME?enablejsapi=1&origin=http%3A%2F%2Ffiddle.jshell.net&autoplay=0&modestbranding=1&wmode=opaque&forceSSL=false

我的测试表明,大多数时候YouTube服务器只是LOCATION:https:// ...对https网址的请求,但大约10%他们用适当的内容提供了http请求.

我想某个问题与强制https有关,但我无法弄清楚解决方案.你有相同的经历吗?你有解决这个问题的方法吗?这是YouTube的错误吗?

我的测试代码:

<div id="myvideo"></div>
<button id="play-button">Play</button>
Run Code Online (Sandbox Code Playgroud)

JS: …

javascript youtube-api

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

具有常见缓动的jQuery动画队列

我有jQuery动画,排队等候一个元素:

var el = $('.elem');

el.animate({
        width: 120
    },
    600,
    'easeInOutQuint'
).animate({
        width: 90
    },
    300,
    'easeInOutQuint'
).animate({
        width: 100
    },
    100,
    'easeInOutQuint'
);
Run Code Online (Sandbox Code Playgroud)

3动画算作1个主动画,只是链接.运行需要1000毫秒,我想在我的例子中使用第一个动画的前60%的缓动,然后在第二个动画中使用缓和的下一个30%,它完成了最后10%的缓动.

有没有办法让缓和作为这些排队动画的全局值?

jquery jquery-animate

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

Safari 位置粘在表格单元格中

我的问题是,当它位于表格单元格中时,位置粘性在 Safari 中不起作用。有没有办法保留表格(因为第二列设置侧边栏上的自动高度)并将侧边栏内容保留在顶部?

table {
    width: 100%;
    table-layout: fixed;
}
td{
    vertical-align: top;
}
.second {
    height: 3000px;
    background: #f00;
    width: 70%;
}
.sidebar div {
    position: sticky;
    position: -webkit-sticky;
    top: 0;
    height: 200px;
    background: #000;
}
Run Code Online (Sandbox Code Playgroud)
<table>
    <tr>
        <td class="sidebar">
            <div></div>
        </td>
        <td class="second"></td>
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

css safari

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

将元素右对齐,边距为左:auto

我想将一个元素对齐到右边.我知道我应该使用float右对齐元素,但是我有一个复杂的项目,我需要理解为什么margin:0 0 0 auto; 在一个案例中将一个元素对齐到右边,以及为什么它在其他情况下不起作用.

当容器是flex容器时,边距:0 0 0 auto; 如您在此示例中所示,将元素对齐到右侧:

div {
  display: flex;
  width: 400px;
  background: #eee;
}

span {
  margin: 0 0 0 auto;
}
Run Code Online (Sandbox Code Playgroud)
<div>
  <span>test</span>
</div>
Run Code Online (Sandbox Code Playgroud)

但是当容器不是弹性容器时,该项目保留在左侧:

div {
  width: 400px;
  background: #eee;
}

span {
  margin: 0 0 0 auto;
}
Run Code Online (Sandbox Code Playgroud)
<div>
  <span>test</span>
</div>
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:

  • 是否可以在不使用容器上的flex的情况下将项目与边缘对齐?
  • Flex示例是如何工作的,还是Flexbox中的错误?

css flexbox

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

为什么col break元素占用了flexbox中的空间

我有以下代码段.它在一行中显示4个列.当您单击任何顶部按钮时,脚本将<div class="break-row" />根据单击的按钮添加一个新元素,该按钮将列拆分为新行.这里的问题是,.break-row即使高度为0px ,元素也会占据垂直空间.我认为在这种情况下.col元素应该填满垂直可用空间.

我的目标是移除灰色的空白区域,并将.col元素拉伸到该区域.这个灰色区域的解释是什么?如何摆脱它?

$('a').on('click', function(e) {
  e.preventDefault();
  $('.break-row').remove();

  var breakAfter = $(this).data('breakafter');
  if (breakAfter > 0) {
    $('<div class="break-row" />').insertAfter('.col:nth-child(' + breakAfter + 'n)');
  }


});
Run Code Online (Sandbox Code Playgroud)
.row {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  background: #222;
  width: 500px;
  height: 500px;
}

.col {
  display: flex;
  flex-flow: column;
  flex: 1 1 auto;
}

.break-row {
  width: 100%;
  flex: 0 0 auto;
  height: 0px;
}

a {
  background: #456;
  padding: …
Run Code Online (Sandbox Code Playgroud)

html css flexbox

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

Magento在小部件中使用自己的句柄不起作用

我发现我可以使用此脚本添加自己的布局句柄:

$this->getLayout()->getUpdate()->addHandle('myhandle');
Run Code Online (Sandbox Code Playgroud)

然后我检查了Alan Storm Layout的观众:http://alanstorm.com/2005/projects/MagentoLayoutViewer.tar.gz

?showLayout =把手

处理此请求

  1. 默认
  2. cms_page
  3. STORE_default
  4. THEME_frontend_default_default
  5. cms_index_index
  6. page_two_columns_left
  7. customer_logged_out
  8. myhandle

有我的句柄,但我的自定义布局xml没有使用.

这是我的xml:

<?xml version="1.0"?>
<layout version="0.1.0">

    <myhandle>
        <reference name="head">
          <action method="addJs"><script>test/your.js</script></action>
        </reference>
    </myhandle>
</layout>
Run Code Online (Sandbox Code Playgroud)

这工作正常,因此加载了xml文件:

<?xml version="1.0"?>
<layout version="0.1.0">

    <default>
        <reference name="head">
          <action method="addJs"><script>test/your.js</script></action>
        </reference>
    </default>
</layout>
Run Code Online (Sandbox Code Playgroud)

怎么了?为什么不能使用这个解决方案?

如果它不是正确的方法,我如何为小部件使用的页面添加自定义css和javascript?

更新:这可能是接近解决方案的东西:

如果我在向页面添加新句柄后添加此代码:

$this->getLayout()->getUpdate()->fetchPackageLayoutUpdates('myhandle');
$this->getLayout()->generateXml();
Run Code Online (Sandbox Code Playgroud)

在此之后,"index.php?showLayout = page"调用在xml中写入句柄代码,但页面不使用它.

widget magento

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

正则表达式匹配 4 个字节的 unicode 字符

我有一个可以在字符串中找到所有 4 字节 unicode 字符的正则表达式。我想让以下内容与所有流行的浏览器兼容。

以下代码在 Chrome 和 Firefox 中运行良好,但 Safari 抛出“无效的正则表达式:字符类中的范围乱序”

var match = 'aaaaaa'.match(/[\u{10000}-\u{10FFFF}]/gu);
Run Code Online (Sandbox Code Playgroud)

所以我的问题是我应该如何更改正则表达式以匹配字符串中的所有 4 字节 unicode 字符,而不使用正则表达式的 unicode 功能。

javascript regex

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

当为touchstart事件调用preventDefault()时,为什么onclick事件被抑制?

我尝试为我的Ipad设备实现一些javascript函数.我想在我的画布div上使用一些滑动动作和点击动作.

我实现了水平和垂直滑动功能.我必须在touchstart事件上使用preventDefault来防止整个页面滚动时滑动.它工作得很好,但在此之后我注意到它禁用了这个div上的每个点击事件.删除preventDefault后,click事件将再次起作用.

有没有解决这个问题的方案?

dojo.connect(this.node, "ontouchstart", this, "touchstart"); 

...   

touchstart: function(e){
    this.touch = dojo.clone(e.changedTouches[0]);
    e.preventDefault();   
}
Run Code Online (Sandbox Code Playgroud)

this.node = document.getElementById('aa');

<div id="aa" style="width: 600px; height: 400px;">
  <div onclick="alert('asd');" style="width: 100px; height: 100px; background-color: #ff0000; margin: auto;">

  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

javascript ipad ios

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

在Gulp中进行concat之后删除原始文件

我想合并我的文件并将其写到单个文件中,然后我想删除原始文件。我应该如何在默认任务中解决此问题?

var es = require('event-stream');
var concat = require('gulp-concat');
var unique = require('array-unique');

function concatGroup(groupName, group){

    return gulp.src(unique(group.files))
        .pipe(concat(groupName + '.js'))
        .pipe(gulp.dest(group.target));
}

gulp.task('default', function () {
    var groups = {
        test: {
            files: [array of files],
            target: "target dir"
        },
        test2: {
            files: [array of files],
            target: "target dir"
        },
        test3: {
            files: [array of files],
            target: "target dir"
        }
    };

    var streams = [];
    for (var groupName in groups) {
        streams.push(concatGroup(groupName, groups[groupName]));
    }
    return es.concat.apply(es, streams);
});
Run Code Online (Sandbox Code Playgroud)

node.js gulp gulp-concat

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

Boost C++ Singleton错误LNK2001:未解析的外部符号"private:static long Nsp :: HL :: flag"(?flag @ HL @ Nsp @@ 0JA)

我尝试创建一个多线程单例模式类.

标题:

class HL{

    public:
        static HL* getInstance();
    .........
    private:
        static HL* instance;
        static boost::once_flag flag;
        HL();
        static void initOnce();
}
Run Code Online (Sandbox Code Playgroud)

CPP:

HL* HL::instance = NULL;

HL* HL::getInstance(){
    if(instance == NULL){
        boost::call_once(flag, initOnce);
    }
    return instance;
}

void HL::initOnce(){
    instance = new HL();
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

error LNK2001: unresolved external symbol "private: static long Nsp::HL::flag" (?flag@HL@Nsp@@0JA)

怎么了?

c++ singleton boost

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