首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >通过设置绘制立方体表面的点的位置来设置旋转

通过设置绘制立方体表面的点的位置来设置旋转
EN

Stack Overflow用户
提问于 2016-08-12 21:49:51
回答 1查看 242关注 0票数 1

我在“我的世界”里用的是.但这不重要。

重要的是,我正在用顶点绘制一个立方体。每个脸都有4个位置点。

首先看一下世界坐标。我按以下顺序向顶点/面添加位置: DCBA.你以后会收到的..(希望如此)

基于此,我是这样绘制立方体的:

代码语言:javascript
运行
复制
public void renderParticles(World w, float x, float y, float z, Tesselator t)
{//**THIS IS AN EXAMPLE METHOD**
int scale = 1;
Random r;

int rotX = r.NextInt(10);
int rotY = r.NextInt(10);
int rotZ = r.NextInt(10);

//front face
     t.addVertex(x,        y,        z);
     t.addVertex(x,        y + scale,z);
     t.addVertex(x + scale,y + scale,z);
     t.addVertex(x + scale,y,        z);

//left face (I might have the Z coords wrong but that doesnt matter right now - basically the other direction)
     t.addVertex(x,          y,        z + scale);
     t.addVertex(x,          y + scale,z + scale);
     t.addVertex(x,          y + scale,z);
     t.addVertex(x,          y,        z);

//back face
     t.addVertex(x + scale,y,        z + scale);
     t.addVertex(x + scale,y + scale,z + scale);
     t.addVertex(x,        y + scale,z + scale);
     t.addVertex(x,        y,        z + scale);

//right face
     t.addVertex(x + scale,y,        z);
     t.addVertex(x + scale,y + scale,z);
     t.addVertex(x + scale,y + scale,z + scale);
     t.addVertex(x + scale,y,        z + scale);

//top face
     t.addVertex(x,        y + scale,z);
     t.addVertex(x,        y + scale,z + scale);
     t.addVertex(x + scale,y + scale,z + scale);
     t.addVertex(x + scale,y + scale,z);

//bottom face
     t.addVertex(x,        y,        z + scale);
     t.addVertex(x,        y,        z);
     t.addVertex(x + scale,y,        z);
     t.addVertex(x + scale,y,        z + scale);
}

当这个立方体产生/绘制时,我希望它已经被随机旋转。

我不知道这么硬的数学..。

,为什么我不把这个贴在地雷锻造论坛上?

这个代码所包含的-The模块是一个coremod(它们在那里不支持它们)

-Actually已经让他们失望了,他们告诉我,首先要把它变成正常的模式。

我有什么想法可以旋转这个立方体(我希望我正确地写出了所有的立方体面:D)?

编辑:

下面是我现在使用的代码,因为我将其更新为mc版本1.10:

代码语言:javascript
运行
复制
/**
 * Renders the particle
 */
public void renderParticle(VertexBuffer worldRendererIn, Entity entityIn, float partialTicks, float rotationX,
        float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
    float f = ((float) this.particleTextureIndexX + this.particleTextureJitterX / 4.0F) / 16.0F;
    float f1 = f + 0.015609375F;
    float f2 = ((float) this.particleTextureIndexY + this.particleTextureJitterY / 4.0F) / 16.0F;
    float f3 = f2 + 0.015609375F;
    float f4 = 0.1F * this.particleScale;

    if (this.particleTexture != null) {
        f = this.particleTexture.getInterpolatedU((double) (this.particleTextureJitterX / 4.0F * 16.0F));
        f1 = this.particleTexture.getInterpolatedU((double) ((this.particleTextureJitterX + 1.0F) / 4.0F * 16.0F));
        f2 = this.particleTexture.getInterpolatedV((double) (this.particleTextureJitterY / 4.0F * 16.0F));
        f3 = this.particleTexture.getInterpolatedV((double) ((this.particleTextureJitterY + 1.0F) / 4.0F * 16.0F));
    }

    float f5 = (float) (this.prevPosX + (this.posX - this.prevPosX) * (double) partialTicks - interpPosX);
    float f6 = (float) (this.prevPosY + (this.posY - this.prevPosY) * (double) partialTicks - interpPosY);
    float f7 = (float) (this.prevPosZ + (this.posZ - this.prevPosZ) * (double) partialTicks - interpPosZ);

    int i = this.getBrightnessForRender(partialTicks);
    int j = i >> 16 & 65535;
    int k = i & 65535;

    if (Minecraft.isFancyGraphicsEnabled() == true) {
        if (spawned == false) {
            this.particleRed *= 1.35F;
            this.particleGreen *= 1.35F;
            this.particleBlue *= 1.35F;

            spawned = true;
        }

        // front
        worldRendererIn.pos(f5 + f4, f6, f7 + f4).tex((double) f, (double) f2)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
        worldRendererIn.pos(f5 + f4, f6 + f4, f7 + f4).tex((double) f, (double) f3)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
        worldRendererIn.pos(f5, f6 + f4, f7 + f4).tex((double) f1, (double) f3)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
        worldRendererIn.pos(f5, f6, f7 + f4).tex((double) f1, (double) f2)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();

        // back
        worldRendererIn.pos(f5, f6, f7).tex((double) f1, (double) f3)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();

        worldRendererIn.pos(f5, f6 + f4, f7).tex((double) f1, (double) f2)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
        // done
        worldRendererIn.pos(f5 + f4, f6 + f4, f7).tex((double) f, (double) f2)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();

        worldRendererIn.pos(f5 + f4, f6, f7).tex((double) f, (double) f3)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();

        // left
        worldRendererIn.pos(f5, f6, f7 + f4).tex((double) f1, (double) f2)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
        worldRendererIn.pos(f5, f6 + f4, f7 + f4).tex((double) f, (double) f2)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
        worldRendererIn.pos(f5, f6 + f4, f7).tex((double) f, (double) f3)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
        worldRendererIn.pos(f5, f6, f7).tex((double) f1, (double) f3)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();

        // right
        worldRendererIn.pos(f5 + f4, f6, f7).tex((double) f, (double) f3)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
        worldRendererIn.pos(f5 + f4, f6 + f4, f7).tex((double) f1, (double) f3)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
        worldRendererIn.pos(f5 + f4, f6 + f4, f7 + f4).tex((double) f1, (double) f2)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
        worldRendererIn.pos(f5 + f4, f6, f7 + f4).tex((double) f, (double) f2)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();

        // top
        worldRendererIn.pos(f5, f6 + f4, f7).tex((double) f1, (double) f3)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
        worldRendererIn.pos(f5, f6 + f4, f7 + f4).tex((double) f1, (double) f2)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
        worldRendererIn.pos(f5 + f4, f6 + f4, f7 + f4).tex((double) f, (double) f2)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
        worldRendererIn.pos(f5 + f4, f6 + f4, f7).tex((double) f, (double) f3)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();

        // bottom
        worldRendererIn.pos(f5, f6, f7 + f4).tex((double) f, (double) f2)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
        worldRendererIn.pos(f5, f6, f7).tex((double) f, (double) f3)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
        worldRendererIn.pos(f5 + f4, f6, f7).tex((double) f1, (double) f3)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
        worldRendererIn.pos(f5 + f4, f6, f7 + f4).tex((double) f1, (double) f2)
                .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
                .endVertex();
    } else {
        worldRendererIn
                .pos((f5 - rotationX * f4 - rotationXY * f4), (double) (f6 - rotationZ * f4),
                        (double) (f7 - rotationYZ * f4 - rotationXZ * f4))
                .tex((double) f, (double) f3).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F)
                .lightmap(j, k).endVertex();
        worldRendererIn
                .pos((double) (f5 - rotationX * f4 + rotationXY * f4), (double) (f6 + rotationZ * f4),
                        (double) (f7 - rotationYZ * f4 + rotationXZ * f4))
                .tex((double) f, (double) f2).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F)
                .lightmap(j, k).endVertex();
        worldRendererIn
                .pos((double) (f5 + rotationX * f4 + rotationXY * f4), (double) (f6 + rotationZ * f4),
                        (double) (f7 + rotationYZ * f4 + rotationXZ * f4))
                .tex((double) f1, (double) f2).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F)
                .lightmap(j, k).endVertex();
        worldRendererIn
                .pos((double) (f5 + rotationX * f4 - rotationXY * f4), (double) (f6 - rotationZ * f4),
                        (double) (f7 + rotationYZ * f4 - rotationXZ * f4))
                .tex((double) f1, (double) f3).color(this.particleRed, this.particleGreen, this.particleBlue, 1.0F)
                .lightmap(j, k).endVertex();
    }
}
EN

回答 1

Stack Overflow用户

发布于 2016-09-05 13:24:12

代码语言:javascript
运行
复制
GL11.glPushMatrix();
float rotateAxis = 1.0f;
float stableAxis = 0.0f;

int degreesPitch = (1+random.nextInt(4))*90;
int degreesRoll = (1+random.nextInt(4))*90;
int degreesYaw = (1+random.nextInt(4))*90;

GL11.glRotate(degreesRoll , stableAxis ,stableAxis ,rotateAxis );
GL11.glRotate(degreesYaw , stableAxis ,rotateAxis ,stableAxis );
GL11.glRotate(degreesPitch ,rotateAxis ,stableAxis ,stableAxis );
//Your tessellator code
tessellator.draw();
GL11.glPopMatrix();

不要做tessellator.addVertex,而是做tessellator.addVertexWithUV(vertexX, vertexY, vertexY, U,V),这样就有了纹理顶点。

别忘了最后给tessellator.draw()打电话。

了解偏航、俯仰和滚动http://howthingsfly.si.edu/flight-dynamics/roll-pitch-and-yaw是有用的

编辑

好吧,你的代码是这样的,这是一个完整的四边形。

代码语言:javascript
运行
复制
    // front
    worldRendererIn.pos(f5 + f4, f6, f7 + f4).tex((double) f, (double) f2)
            .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
            .endVertex();
    worldRendererIn.pos(f5 + f4, f6 + f4, f7 + f4).tex((double) f, (double) f3)
            .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
            .endVertex();
    worldRendererIn.pos(f5, f6 + f4, f7 + f4).tex((double) f1, (double) f3)
            .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
            .endVertex();
    worldRendererIn.pos(f5, f6, f7 + f4).tex((double) f1, (double) f2)
            .color(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha).lightmap(j, k)
            .endVertex();

要绘制四角图,您需要设置您的世界呈现器模式。

代码语言:javascript
运行
复制
   //OpenGL enable/blend functions/etc... here
   // for example GL11.glScalef(scale, scale, scale);

   worldrenderer.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR_NORMAL);

   // your vertex defining code
   // your vertex defining code
   // your vertex defining code

    worldRendererIn.normal(0.0f, 0.0f, 1.0f);


   tessellator.draw();
   // OPENGL disable code here

最后一行tesselator.draw()将确保它被绘制到屏幕上,顶点缓冲区被刷新到一个显示列表中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38926935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档