问题总结笔记

1.向量旋转

       问题: 将一个向量旋转90

        方法:旋转矩阵

FVector FrontDir = EndMousePoint - Point;
FrontDir.Normalize();
FVector Left = FVector(-FrontDir.Y, FrontDir.X, 0);
Verties.Add(Point + Left * (WallWedith / 2));
Verties.Add(FVector(Verties[0].X, Verties[0].Y, Verties[0].Z + WallHeight));
Verties.Add(Point - Left * (WallWedith / 2));
Verties.Add(FVector(Verties[2].X, Verties[2].Y, Verties[2].Z + WallHeight));
Verties.Add(EndMousePoint - Left * (WallWedith / 2));
Verties.Add(FVector(Verties[4].X, Verties[4].Y, Verties[4].Z + WallHeight));
Verties.Add(EndMousePoint + Left * (WallWedith / 2));
Verties.Add(FVector(Verties[6].X, Verties[6].Y, Verties[6].Z + WallHeight));

Point:起点坐标, EndMousePoint:终点坐标。

依次加入点的坐标,WallWedith:立方体的宽,WallHeight:立方体的高。

2.ProceduralMeshActor

问题:利用ProceduralMeshActor创建立方体

//侧面
for (int32 i = 0; i < Verties.Num() - 1; i = i + 2) {

	Triangles.Add(i);
	Triangles.Add((i+2)% Verties.Num());
	Triangles.Add(i+1);
	Triangles.Add(i+1);
	Triangles.Add((i+2)% Verties.Num());
	Triangles.Add((i+3) % Verties.Num());
}

//上下面
for (int32 i = 0; i < 2; i++) {
	for (int32 j = 0; j < Verties.Num(); j++) {
		if (j % 2 == i) {
			Triangles.Add(j);
		}
	}
	Triangles.Add(i);
	Triangles.Add(i+4);

}

先构建一个侧面,通过循环构建所有侧面,上下面单独处理

3.鼠标屏幕坐标转换成空间坐标(有偏差,有待改进) 


FVector2D MousePosition;

UWorld* world = GetWorld();
if (world)
{
	APlayerController* pc = world->GetFirstPlayerController();
	if (pc)
	{
		ULocalPlayer* LocalPlayer = pc->GetLocalPlayer();
		if (LocalPlayer && LocalPlayer->ViewportClient)
		{
			LocalPlayer->ViewportClient->GetMousePosition(MousePosition);
		}
	}
}

float Scale = UWidgetLayoutLibrary::GetViewportScale(this);

FVector WorldLocation;
FVector WorldDirection;
APlayerController::DeprojectScreenPositionToWorld(MousePosition.X, MousePosition.Y, WorldLocation,WorldDirection);

MouseLocal = FVector(WorldDirection.X * 1000/ Scale, WorldDirection.Y * 1000/ Scale, 0);

记得在Build.cs文件里添加"UMG"

相关推荐

  1. Ceisum 问题总结

    2024-04-22 20:36:07       56 阅读
  2. Redisson出现问题总结

    2024-04-22 20:36:07       55 阅读
  3. 股票问题总结

    2024-04-22 20:36:07       66 阅读
  4. 疑惑问题总结

    2024-04-22 20:36:07       54 阅读
  5. 跨域问题总结

    2024-04-22 20:36:07       51 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-22 20:36:07       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-22 20:36:07       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-22 20:36:07       87 阅读
  4. Python语言-面向对象

    2024-04-22 20:36:07       96 阅读

热门阅读

  1. 第七周笔记

    2024-04-22 20:36:07       30 阅读
  2. MySQL运维故障排查与高效解决方案

    2024-04-22 20:36:07       36 阅读
  3. 机器学习笔记 - torch.hub 和 torchvision.models 的区别

    2024-04-22 20:36:07       33 阅读
  4. MySQL运维故障解决方案:实战案例与深度解析

    2024-04-22 20:36:07       32 阅读
  5. JWT原理

    JWT原理

    2024-04-22 20:36:07      37 阅读
  6. Docker - 网络

    2024-04-22 20:36:07       32 阅读
  7. MySQL无法远程连接方案解决(示例)

    2024-04-22 20:36:07       38 阅读
  8. 卸载jenkins和docker

    2024-04-22 20:36:07       35 阅读
  9. 算法=问题的解决方法

    2024-04-22 20:36:07       39 阅读
  10. Unity中Socket,Tcp,Udp网络连接协议总结

    2024-04-22 20:36:07       29 阅读
  11. 浅谈薪酬绩效设计及运行的忌讳

    2024-04-22 20:36:07       38 阅读
  12. ubuntu用户与用户组管理

    2024-04-22 20:36:07       37 阅读