环境配置使用的是VSCODE + WSL2 进行的配置
作为自己配置的记录,主要教程来自 # 在 Win10 下配置 GAMES101 开发环境(WSL2)
启用 Windows 子系统(WSL)功能#
在 PowerShell(管理员模式)中运行:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux/all /norestart解释:
/all:在所有用户上启用该功能/norestart:启用功能后不会立即重启
启用虚拟机平台功能#
WSL2 依赖 Windows 虚拟机功能,需要额外启用:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart将 WSL 默认版本设置为 WSL2(视情况而定)#
wsl --set-default-version 2Windows 11 默认已安装 WSL2,不需要执行该命令。
Windows 10 用户 需要执行此命令,否则默认使用 WSL1。
然后可以去Microsoft Store 下载 Ubuntu20.04
安装g++和CMake#
sudo apt update
sudo apt install build-essential cmake 安装 eigen3 和 opencv#
sudo apt install libopencv-dev libeigen3-dev作业7提高题需要使用多线程,如果使用 pthread 库的话,需要修改 CMakeList.txt 文件将 pthread 链接到程序中,在 CMakeList.txt 文件中增加如下文件即可:
find_package (Threads)
target_link_libraries (RayTracing Threads::Threads)执行如下命令安装作业8使用的 OpenGL 相关开发库(请参考作业8说明文件)
sudo apt install libglu1-mesa-dev freeglut3-dev mesa-common-dev xorg-dev关于作业8的运行说明,请参考 MobaXTerm 的 使用方法小节
编译测试#
WSL可以直接访问 Windows 的文件系统,但是注意路径有所变化,例如 D盘会被映射到 /mnt/d,所以举例来说,我的 GAMES101 作业0目录在 D:\Git\GAMES101\Assignment0 下,在 WSL 下的路径就变成了 /mnt/d/Git/GAMES101/Assignment0 。
以作业0为例举例,编译测试方法为:
cd /mnt/d/Git/GAMES101/Assignment0
mkdir build
cd build
cmake ../
make作业0 的CmakeLists.txt
cmake_minimum_required (VERSION 3.22.1)
project (Transformation)
find_package(Eigen3 REQUIRED)
include_directories(EIGEN3_INCLUDE_DIR)
add_executable (Transformation main.cpp)代码 main.cpp
#include <cmath>
#include <eigen3/Eigen/Core>
#include <eigen3/Eigen/Dense>
#include <iostream>
int main() {
// Basic Example of cpp
std::cout << "Example of cpp \n";
float a = 1.0, b = 2.0;
std::cout << a << std::endl;
std::cout << a / b << std::endl;
std::cout << std::sqrt(b) << std::endl;
std::cout << std::acos(-1) << std::endl;
std::cout << std::sin(30.0 / 180.0 * acos(-1)) << std::endl;
// Example of vector
std::cout << "Example of vector \n";
// vector definition
Eigen::Vector3f v(1.0f, 2.0f, 3.0f);
Eigen::Vector3f w(1.0f, 0.0f, 0.0f);
// vector output
std::cout << "Example of output \n";
std::cout << v << std::endl;
// vector add
std::cout << "Example of add \n";
std::cout << v + w << std::endl;
// vector scalar multiply
std::cout << "Example of scalar multiply \n";
std::cout << v * 3.0f << std::endl;
std::cout << 2.0f * v << std::endl;
// Example of matrix
std::cout << "Example of matrix \n";
// matrix definition
Eigen::Matrix3f i, j;
i << 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0;
j << 2.0, 3.0, 1.0, 4.0, 6.0, 5.0, 9.0, 7.0, 8.0;
// matrix output
std::cout << "Example of output \n";
std::cout << i << std::endl;
// matrix add i + j
// matrix scalar multiply i * 2.0
// matrix multiply i * j
// matrix multiply vector i * v
return 0;
}输出
pan@DESKTOP-IO8PALN:~/games101study/build$ /home/pan/games101study/build/Transformation
Example of cpp
1
0.5
1.41421
3.14159
0.5
Example of vector
Example of output
1
2
3
Example of add
2
2
3
Example of scalar multiply
3
6
9
2
4
6
Example of matrix
Example of output
1 2 3
4 5 6
7 8 9