小编ath*_*aos的帖子

在bash中,"for; do echo; done"在空格处分割行

在Mac OSX上的bash中,我有一个包含行的文件(测试用例)

x xx xxx
xxx xx x
Run Code Online (Sandbox Code Playgroud)

但是当我执行命令时

for i in `cat r.txt`; do echo "$i"; done
Run Code Online (Sandbox Code Playgroud)

结果不是

x xx xxx
xxx xx x
Run Code Online (Sandbox Code Playgroud)

正如我想要的那样

x
xx
xxx
xxx
xx
x
Run Code Online (Sandbox Code Playgroud)

我怎么做回声给我'x xx xxx'?

macos bash echo

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

澄清为什么这个C代码工作

我今天正在学习C. 我已经用托管语言(Java,C#,Python等)编写了一段时间.我以为我正在理解指针的细节,但后来我写了下面的代码按预期工作,但生成了一个'不兼容的指针类型'警告.

void setText(char* output) {
    //code to set output to whatever, no problems here.
}

int main(int argc, const char* argv[]) {
    char output[10];

    setText(&output);

    //[EDITED] ...other test code which printf's and further manipulates output.

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

所以我用Google搜索,最后改变了这条线

setText(&output);
Run Code Online (Sandbox Code Playgroud)

setText(output);
Run Code Online (Sandbox Code Playgroud)

摆脱了警告.但现在我不知道为什么第一个人正在工作.就我所知,我正在发送一个地址的地址(因为char*x;与char x [];本质上是相同的).我误解了什么,为什么这两个都有效?

c pointers

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

房间内的光源意外地起作用

我写了几个Android应用程序,但这是我第一次使用3D编程.

我创造了一个房间(4个墙壁,天花板和地板),里面有几个物体,能够像走路一样移动相机.我用各种图像纹理所有表面,一切都按预期工作.

根据具体情况,房间宽14个单位,深16个单位(以原点为中心),高3个单位(原点1个,下面2个).房间中间有两个物体,一个立方体和一个倒金字塔.

然后我去添加一个光源来遮蔽立方体和金字塔.我读过并关注了几个NeHe的端口,所以我把我在课程中工作的内容用于照明并将其应用到我的新代码中.

gl.glEnable(GL10.GL_LIGHTING);
gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, new float[] { 0.1f, 0.1f, 0.1f, 1f }, 0);
gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, new float[] { 1f, 1f, 1f, 1f }, 0);
gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, new float[] { -4f, 0.9f, 6f, 1f }, 0);
gl.glEnable(GL10.GL_LIGHT0);
Run Code Online (Sandbox Code Playgroud)

结果是立方体和金字塔没有阴影.它们在与光相对的两侧看起来和在面对它时一样.当摄像机直接指向远离光源时,房间看起来就像我添加照明代码之前一样.当我将相机旋转到面向光源时,整个房间(包括物体)会变暗,直到相机直接面向光源时全黑.

这里发生了什么?我阅读了很多关于灯光及其工作原理的文章,但我没有看到任何迹象表明为什么这不会照亮房间的所有侧面,立方体和金字塔根据灯光位置着色.是否有一些预期的光线行为,因为它在房间"内部"?我只是因为我是新手而错过了一些简单的东西吗?

java android lighting opengl-es

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

在Android中使用Looper.prepare()的细节

我在理解如何使用Looper prepare()/ loop()/ quit()逻辑方面遇到了一些麻烦.

我有三个线程:一个是UI线程,一个是游戏逻辑线程,最后一个是网络通信线程(后台线程,只在使用时生存).

游戏线程对网络调用的结果有很多依赖性,所以我想从游戏线程中旋转网络线程Handler并将结果发回.

当然,由于没有涉及UI线程,我需要在Looper.prepare()某个地方调用... 我认为它应该在游戏线程中调用,但我不能这样做,因为loop()接管它.

如何使用我的处理程序从网络线程回发到游戏线程?

multithreading android looper

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

在GLKit中使用GL_POINTS(iOS 5)

使用OpenGL的新功能,我使用GL_LINE_LOOP在iOS 5上使用GLKit成功显示行,但使用GL_POINTS显示点给我带来了麻烦.具体来说,除了单个像素,我无法显示任何内容.我在网上搜索没有成功,所以我希望有人可以指出我缺少的东西.

这是我的测试代码......

//positions and colors, vertices and indices...
typedef struct {
    float Position[2];
    float Color[4];
} Vertex;

const Vertex Vertices[] = {
    {{50, 50}, {0, 0, 1, 1}},
    {{200, 50}, {0, 0, 1, 1}},
    {{200, 200}, {0, 0, 1, 1}},
    {{50, 200}, {0, 0, 1, 1}}
};

const GLubyte Indices[] = {
    0, 1, 2, 3
};


@interface AppViewController() {
    GLuint _vertexBuffer;
    GLuint _indexBuffer;
}

...
//some unrelated properties, the @implementation and other methods
...

- (void)viewDidLoad {
    [super …
Run Code Online (Sandbox Code Playgroud)

ios opengl-es-2.0 glkit

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

标签 统计

android ×2

bash ×1

c ×1

echo ×1

glkit ×1

ios ×1

java ×1

lighting ×1

looper ×1

macos ×1

multithreading ×1

opengl-es ×1

opengl-es-2.0 ×1

pointers ×1