小编spi*_*ing的帖子

#ifndef没有按预期工作

获取LNK2005"已在GUI.obj中定义"以获取PAL.h中的函数指针

//GUI.cpp
#include "PAL.h"

//PAL.h
#define PAL_INCLUDE
int (*addPAL)( int, void(*)(), void(*)() );

//main.cpp
#include "GUI.h"
#ifndef PAL_INCLUDE
#include "PAL.h"
#endif
Run Code Online (Sandbox Code Playgroud)

我误解了包含的本质#ifndef吗?

c++ include c-preprocessor

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

模型视图投影中的第四行是查看位置吗?

我想从相机的方向照亮顶点水平的平坦表面。我希望旋转视图时灯光不会改变,但当我稍微移开视线时灯光最亮。mvp[3] 不是像我想象的那样是相机坐标吗?

#version 450
in vec3 vertex;
uniform mat4 mvp;
out vec4 color;

void main()
{
    gl_Position =  mvp * vec4(vertex,1.);
    vec3 n = vec3(0.,0.,1.);
    vec3 v = normalize( vec3(mvp[3])-vertex );
    //I tried the other direction in the mat4
    //vec3(mvp[0][3],mvp[1][3],mvp[2][3]);

    color = vec4( dot(v,n) );
}
Run Code Online (Sandbox Code Playgroud)

opengl shader glsl perspectivecamera coordinate-transformation

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

将文本字符串与函数关联

这是我的解决方案,它需要测试运行来计算const值才能运行.这很尴尬,你有更优雅的解决方案吗?我以为我会避免用这种方式调用100个字符串比较.

//find these values before hand
char a[] = "SHET"; //1413826643
char b[] = "ANIM"; //1296649793
char c[] = "RGST"; //1414743890
int* get_word_value[] = { (int*)a, (int*)b, (int*)c };

//enum in header file makes it externally linked and compatible with switch statement
enum str_command{ SHET = 1413826643, ANIM = 1296649793, RGST = 1414743890 } ;
//cpp:
char* file = readTXT( "text.txt" );
int* command = (int*)file;
switch( command ) {
case SHET: SHETfunc( file ); break;
case ANIM: ANIMfunc( file …
Run Code Online (Sandbox Code Playgroud)

c++ string

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