-
Notifications
You must be signed in to change notification settings - Fork 11
Projector(投影器)
Zoyn edited this page Jun 14, 2021
·
4 revisions
投影器算法由 @Bryan33 所提供,所谓投影器则是向量的投影,通过投影器,我们可以将原本2D或3D的图形,利用投影器投射至你所给定的向量的朝向上
投影器目前有两种,TwoDProjector和ThreeDProjector, TwoDProjector则是只会投影2D的图像,如果你原本要投影一个3D的图形, 那么则只会投射一个2D的平面,ThreeDProjector则是会投影出3D的图形出来,具体使用方法可以翻阅代码
Vector vector = player.getLocation().getDirection();
Location location = player.getLocation();
World world = location.getWorld();
BiFunction<Double, Double, Location> method = TwoDProjector.create2DProjector(location, vector);
Bukkit.getScheduler().runTaskTimer(this, () -> {
for (int i = 0; i < 360; i++) {
double rad = Math.toRadians(i);
double x = Math.cos(rad);
double z = Math.sin(rad);
// 通过投影器开始转换坐标
Location loc = method.apply(x, z);
world.spawnParticle(Particle.VILLAGER_HAPPY, loc, 1, 0, 0, 0, 0);
}
}, 0L, 10L);
具体效果:
Vector vector = player.getLocation().getDirection();
Location location = player.getLocation();
World world = location.getWorld();
ThreeDProjector projector = new ThreeDProjector(location, vector);
Bukkit.getScheduler().runTaskTimer(this, () -> {
double y = 0;
for (int i = 0; i < 8 * 360; i += 20) {
double rad = Math.toRadians(i);
double x = Math.cos(rad);
y += 0.1;
double z = Math.sin(rad);
// 通过投影器开始转换坐标
Location loc = projector.apply(x, y, z);
world.spawnParticle(Particle.VILLAGER_HAPPY, loc, 1, 0, 0, 0, 0);
}
}, 0L, 10L);
具体效果:
阿巴阿巴阿巴阿巴