这个问题与What does 'super' do in Python? 的帖子有关。,如何初始化基(超)类?和Python:如何从超类创建子类?SuperClass它描述了从SubClassas内部初始化 a 的两种方法
class SuperClass:
def __init__(self):
return
def superMethod(self):
return
## One version of Initiation
class SubClass(SuperClass):
def __init__(self):
SuperClass.__init__(self)
def subMethod(self):
return
Run Code Online (Sandbox Code Playgroud)
或者
class SuperClass:
def __init__(self):
return
def superMethod(self):
return
## Another version of Initiation
class SubClass(SuperClass):
def __init__(self):
super(SubClass, self).__init__()
def subMethod(self):
return
Run Code Online (Sandbox Code Playgroud)
所以我对需要在
and
中显式传递self参数
感到有点困惑。(事实上,如果我打电话我会得到错误SuperClass.__init__(self)super(SubClass, self).__init__()SuperClass.__init__()
TypeError: __init__() missing 1 required positional argument: …Run Code Online (Sandbox Code Playgroud) 我正在尝试用C++创建一个需要多个对象构造函数的对象.说Foo()和Foo(int)地方Foo(int)然后调用Foo().简化代码如下:
#include <iostream>
class Foo{
private:
int iX;
public:
void printX(string sLabel){
cout << sLabel << " : " << " Foo::iX = " << Foo::iX << endl;
};
void setX(int iX){
Foo::iX = iX;
Foo::printX("setX(void) Method");
};
Foo(){
Foo::iX = 1;
Foo::printX("Foo(void) Constructor");
};
Foo(int iX){
Foo::setX(iX);
Foo::printX("Foo(int) Constructor");
Foo::Foo();
Foo::printX("Foo(int) Constructor");
};
};
int main( int argc, char** argv ){
Foo bar(2);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
其输出是
setX(void) Method : Foo::iX …Run Code Online (Sandbox Code Playgroud) 我对ARRAY_INDEX_BUFFER(索引缓冲区)与ARRAY_BUFFER (数组缓冲区)的使用有点困惑,并且正在寻求澄清/更好的理解。
具体来说,我很困惑(考虑到多个数组缓冲区的存在)WebGL 和索引缓冲区如何知道要引用哪个数组缓冲区?*
使用从Mozilla 的使用 WebGL 演示创建 3D 对象获得的代码 作为基础,我理解数组缓冲区的分配和初始化为
cubeVerticesBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, cubeVerticesBuffer);
var vertices = [
// Front face
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, 1.0, 1.0,
// Back face
-1.0, -1.0, -1.0,
-1.0, 1.0, -1.0,
1.0, 1.0, -1.0,
1.0, -1.0, -1.0,
// Top face
-1.0, 1.0, -1.0,
-1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
1.0, 1.0, -1.0,
// Bottom face
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
1.0, -1.0, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用函数指针(fnPtr)从另一个类方法(在本例中为构造函数)中引用类方法(fnEmpty).
安装程序main.cpp是
#include <iostream>
#include "test.hpp"
int main(int argc, char* argv[]){
Test test;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
和一个读取的test.hpp
#ifndef _test_h
#define _test_h
#include <iostream>
class Test {
private:
public:
void (*ptrEmpty)(void);
void fnEmpty(){ std::cout << "Got Here" << std::endl;};
Test(){ ptrEmpty = fnEmpty; };
~Test(){};
};
#endif
Run Code Online (Sandbox Code Playgroud)
网络细节上的大多数材料都能够从类外部引用类方法(请参阅microsoft page和newty.de),但不能从类内部引用(就像我所做的那样).
使用上述文件会出错
在main.cpp中包含的文件中:6:./ test.hpp:11:21:错误:必须调用对非静态成员函数的引用;
那么1)为什么会出现这种错误?
如果我将第10行的fnPtr声明更改为静态,那么它就会读取
static void fnEmpty(){ std::cout …Run Code Online (Sandbox Code Playgroud) 我试图了解glFrustum()在OpenGL中创建的投影矩阵,以及将其转换为x = [-1,1],y = [-1,1]和z = [-1的规范化设备坐标的转换,1]和发生的一系列4x4矩阵乘法,得出的投影矩阵为
我知道最终结果(在NDC中)是通过应用连续变换后除以w分量获得的,但是那些连续变换又是什么呢?
那就是表达式中的矩阵T(就近,远,左,右,上,下变量而言)
这样每个T仅代表scale,平移,旋转或剪切运算/变换?
我读了一些有关OpenGL LH或RH的文章,以及Projection Matrix教程,但是我对正在进行的基本操作(例如,缩放,平移,旋转或剪切操作)仍然不了解。
有没有一种方法可以创建多个着色器(包括顶点、片段、甚至几何体和曲面细分),它们可以在它们的作用中进行组合?
例如:我在更高版本的 OpenGL 中看到了in和out关键字的许多用法,并将使用这些来说明我的问题。
有没有给定着色器的方法(哪个无关紧要,但可以说是片段着色器),例如
in inVar;
out outVar;
void man(){
var varOne = inVar;
var varTwo = varOne;
var varThr = varTwo;
outVar = varThr;
}
Run Code Online (Sandbox Code Playgroud)
把它变成片段着色器
in inVar;
out varOne;
void main(){
varOne = inVar;
}
Run Code Online (Sandbox Code Playgroud)
其次是片段着色器
in varOne;
out varTwo;
void main(){
varTwo = varOne;
}
Run Code Online (Sandbox Code Playgroud)
其次是片段着色器
in varTwo(
out varThr;
void main(){
varThr = varTwo
}
Run Code Online (Sandbox Code Playgroud)
最后是片段着色器
in varThr;
out outVar;
void main(){
outVar = varThr;
}
Run Code Online (Sandbox Code Playgroud)
是在和出正确的“概念”来形容这种行为或我应该寻找另一个关键字?