
Lv.1
很多人把画面作为评价一个作品的标准,然而我不那么认为,我认为一个游戏应该是玩法占大头
签名:这么想来,我在bcm已有将近6年的时间了,如今也应该做个告别 是的,我退猫了 3年的时间我在和大伙一样用2D 而我却又花了3年的时间研究了3D 开发了光线追踪,空间音频,导入外部模型,遮挡剔除,光栅化,LOD... 以及众多版本的3D游戏引擎,建立起了一个完整的bcm3D游戏工作流 但是那也只是过去的事了 不论是bcm也好,ccw也好,但是它们都已经不适合我了,但是在这累计的一些经验却是十分有用的 以后我主要在stream上发布作品,使用Godot进行创作
在 构思编程猫 中回复
你还别说,我之前给kitten测过速
结果是这样的
NO.1 kitten3
NO.2 kitten4
NO.3 kittenN
在这几个版本里kitten3是最快的,可能Nome更快
2024-07-07T19:11:42 点赞:0
在 【讨论】该怎让优化3D引擎才能达到不低于10帧的情况下渲染10000给三角形? 中回复
我认为要在不低于10帧的情况下渲染10000个三角形应该需要两个角色并行运算
然后还得有一个顶点缓存
2024-07-08T14:48:35 点赞:0
在 C++!!! 中回复
#include <iostream>
#include <cmath>
const int screenWidth = 80; // 输出屏幕的宽度
const int screenHeight = 40; // 输出屏幕的高度
struct Vec3 {
double x, y, z;
Vec3(double x_ = 0, double y_ = 0, double z_ = 0) : x(x_), y(y_), z(z_) {}
double lengthSquared() const {
return x * x + y * y + z * z;
}
double length() const {
return sqrt(lengthSquared());
}
Vec3 normalize() const {
double len = length();
return Vec3(x / len, y / len, z / len);
}
Vec3 operator+(const Vec3& rhs) const {
return Vec3(x + rhs.x, y + rhs.y, z + rhs.z);
}
Vec3 operator-(const Vec3& rhs) const {
return Vec3(x - rhs.x, y - rhs.y, z - rhs.z);
}
Vec3 operator*(double scalar) const {
return Vec3(x * scalar, y * scalar, z * scalar);
}
double dot(const Vec3& rhs) const {
return x * rhs.x + y * rhs.y + z * rhs.z;
}
Vec3 cross(const Vec3& rhs) const {
return Vec3(y * rhs.z - z * rhs.y,
z * rhs.x - x * rhs.z,
x * rhs.y - y * rhs.x);
}
};
struct Sphere {
Vec3 center;
double radius;
Sphere(const Vec3& center_, double radius_) : center(center_), radius(radius_) {}
bool intersect(const Vec3& orig, const Vec3& dir, double& t) const {
Vec3 oc = orig - center;
double a = dir.dot(dir);
double b = 2.0 * oc.dot(dir);
double c = oc.dot(oc) - radius * radius;
double discriminant = b * b - 4 * a * c;
if (discriminant < 0) return false;
double sqrtD = sqrt(discriminant);
double t1 = (-b - sqrtD) / (2.0 * a);
double t2 = (-b + sqrtD) / (2.0 * a);
if (t1 > t2) std::swap(t1, t2);
if (t1 < 0) {
t1 = t2;
if (t1 < 0) return false;
}
t = t1;
return true;
}
};
char rayTrace(const Vec3& orig, const Vec3& dir, const Sphere& sphere) {
double t;
if (sphere.intersect(orig, dir, t)) {
Vec3 hitPoint = orig + dir * t;
Vec3 normal = (hitPoint - sphere.center).normalize();
double intensity = normal.dot(Vec3(1, 1, 1).normalize());
const char chars[] = "@%#*+=-:. ";
int charIdx = static_cast<int>(intensity * (sizeof(chars) - 1));
return chars[charIdx];
}
return ' ';
}
int main() {
Sphere sphere(Vec3(0, 0, -10), 3.0);
double screenDist = 10.0;
for (double t = 0; t < 100; t += 0.1) {
Vec3 cameraPos(6 * cos(t), 0, 10 * sin(t));
for (int y = 0; y < screenHeight; ++y) {
for (int x = 0; x < screenWidth; ++x) {
double screenX = (2.0 * x - screenWidth) / double(screenWidth);
double screenY = (2.0 * y - screenHeight) / double(screenHeight);
Vec3 rayDir(screenX, -screenY, -screenDist);
rayDir = rayDir.normalize();
char pixel = rayTrace(cameraPos, rayDir, sphere);
std::cout << pixel;
}
std::cout << std::endl;
}
std::cout << "\x1b[H";
}
return 0;
}
光线追踪
2024-07-10T13:54:29 点赞:0