我正在为 OBJ 文件制作一个文件解析器,所有内容都会进入正确的位置,但由于某种原因它不会运行到文件末尾。
void loader::readIn()
{
//!takes in the all the data and
//!puts in string first.
std::string line;
while(!myFile.eof())
{
linetype = unknown;//enum set to uknown
line.clear(); // clear line
ss.clear(); // clear string stream
std::getline(myFile,line); //intake line , to string line
//found = line.find("v "); //enum to check the line type i,e Face ,vertex
if(line[0] == 'v') //! check to see if the first char is v
{
linetype = vertex;
}
// found = line.find("f ");
if(line[0] …Run Code Online (Sandbox Code Playgroud) 所以我读到当变量在c ++中声明时,如果你想获得最佳的缓存读取,那么内存应该坚持其自然对齐.例:
int a; // memory address should end in 0x0,0x4,0x8,0xC
int b[2]; // 8 bytes 0x0,0x8
int b[4]; // 16 bytes 0x0
Run Code Online (Sandbox Code Playgroud)
但实际上这些变量并不遵循"自然对齐"规则,16字节变量驻留在以0xC结尾的存储器地址中.为什么是这样 ?
我对这些事实可能是错的,所以纠正我吧!
一个指针指向一个内存地址,如果你去了这个内存地址你会找到一个字节?指针也指向它指向的内存段的最低地址,所以如果它指向一个8字节的内存段,从0x0开始到0x7结束,它将指向0x0?
指针如何知道它指向的内存大小?因此,如果一个指针指向一个128字节大小的内存段并且指针被转换为另一种类型,那么内存段的大小会发生什么变化呢?
我收到错误,完全不知道为什么!
//create a circle shape.
sf::CircleShape shape;
shape.setRadius(25);
shape.setFillColor(sf::Color(100,250,250));
//circle collision geometry
circle circleTest(shape.getPosition.x,shape.getPosition.y,shape.getRadius())
Run Code Online (Sandbox Code Playgroud)
Circle是圆形碰撞几何体的类.它在构造函数上失败
(shape.getPosition.x,shape.getPosition.y,shape.getRadius())
我不知道为什么我得到错误,它工作正常然后突然给了我标题中的错误.
我一直在使用以下方法测试两个圆圈之间的碰撞:
Circle A = (x1,y1) Circle b = (x2,y2)
Radius A Radius b
x1 - x2 = x' * x'
y1 - y2 = y' * y'
x' + y' = distance
square root of distance - Radius A + Radius B
Run Code Online (Sandbox Code Playgroud)
如果得到的答案是负数,则它是相交的.
我在测试中使用了这种方法,但它似乎并不是非常准确.
bool circle::intersects(circle & test)
{
Vector temp;
temp.setX(centre.getX() - test.centre.getX());
temp.setY(centre.getY() - test.centre.getY());
float distance;
float temp2;
float xt;
xt = temp.getX();
temp2 = xt * xt;
temp.setX(temp2);
xt = temp.getY();
temp2 = xt * xt; …Run Code Online (Sandbox Code Playgroud)