- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试使用 libgdx 来渲染一些 fbx 模型,我成功地做到了,但我卡在了一个点上。
我在 ModelInstance 的帮助下渲染一个篮球 fbx 文件,现在我想在那个篮球上画一个文本。我可以在篮球上画文字,但它是线性的,看起来不像是那个篮球的一部分。我希望文本以与那个球相同的曲线方式显示。
这就是我绘制文本的方式--
batch = new SpriteBatch();
batch.setProjectionMatrix(camera.combined);
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("font/Lato-Bold.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 30;
parameter.color = com.badlogic.gdx.graphics.Color.WHITE;
parameter.magFilter = Texture.TextureFilter.Linear; // used for resizing quality
parameter.minFilter = Texture.TextureFilter.Linear;
generator.scaleForPixelHeight(3);
BitmapFont aFont = generator.generateFont(parameter);
aFont.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
aFont.draw(batch, options.get(i), aBound.getCenterX(), aBound.getCenterY() + textHeight / 2);
Where aBound --> 模型的 BoundingBox(即 BasketBall)
最佳答案
您在此处尝试实现的目标在 libGdx 中略微复杂。但是,您的方法是不正确的,因为您将文本绘制为球顶部的单独 Sprite 对象。
实现此目的的正确过程是将文本绘制到纹理上,然后将纹理映射并绑定(bind)到球上。
程序可以分为4个部分-
请注意,我想提一下,可以使用任何其他纹理,如果您不想实时更新文本,您可以轻松地将预制纹理与您想要的任何文本一起使用我喜欢。
代码如下-
设置字体生成和帧缓冲区对象
//Create a new SpriteBatch object
batch = new SpriteBatch();
//Generate font
FreeTypeFontGenerator generator = new
FreeTypeFontGenerator(Gdx.files.internal("font/Lato-Bold.ttf"));
FreeTypeFontGenerator.FreeTypeFontParameter parameter = new
FreeTypeFontGenerator.FreeTypeFontParameter();
parameter.size = 30;
parameter.color = com.badlogic.gdx.graphics.Color.WHITE;
parameter.magFilter = Texture.TextureFilter.Linear; // used for resizing quality
parameter.minFilter = Texture.TextureFilter.Linear;
generator.scaleForPixelHeight(10);
//Get bitmap font
BitmapFont aFont = generator.generateFont(parameter);
aFont.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear,
Texture.TextureFilter.Linear);
//Generate new framebuffer object of 128x128 px. This will be our texture
FrameBuffer lFb = new FrameBuffer(Pixmap.Format.RGBA4444,128,128,false);
设置 Sprite 批处理
//Set the correct resolution for drawing to the framebuffer
lFb.begin();
Gdx.gl.glViewport(0,0,128,128);
Gdx.gl.glClearColor(1f, 1f, 1f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Matrix4 lm = new Matrix4();
//Set the correct projection for the sprite batch
lm.setToOrtho2D(0,0,128,128);
batch.setProjectionMatrix(lm);
最后将文字绘制到纹理上
batch.begin();
aFont.draw(batch,"Goal!",64,64);
batch.end();
lFb.end();
将纹理映射到模型
//Generate the material to be applied to the ball
//Notice here how we use the FBO's texture as the material base
Material lMaterial = new Material(TextureAttribute.createDiffuse(lFb.getColorBufferTexture()));
//Since I do not have a sphere model, I'll just create one with the newly
//generated material
ballModel = mb.createSphere(1.0f,1.0f,1.0f,8,8,lMaterial,
VertexAttributes.Usage.Position | VertexAttributes.Usage.Normal | VertexAttributes.Usage.TextureCoordinates);
//Finally instantiate an object of the model
ballInstance = new ModelInstance(ballModel);
渲染模型
mBatch.begin(mCamera);
mBatch.render(ballInstance);
mBatch.end();
//Rotate the ball along the y-axis
ballInstance.transform.rotate(0.0f,1.0f,0.0f,0.5f);
结果 -
关于android - 在 libgdx 中在球体上绘制文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43542081/
我一直在尝试根据内部“ Shiny 球体”图案在球体上产生发光效果,但一直坚持定位“球体”的某些方面。 就目前而言,我的 CSS 看起来像这样: .sphere { height: 200px;
我正在尝试使用下面给出的旋转矩阵来旋转“轨道”: [cos(angle) -sin(angle) 0; sin(angle) cos (angle) 0; 0 0
我有一组由地理 (WGS84) 坐标指定的多边形:它们位于一个球体上。 我有一个由经纬度对指定的点。 我想(有效地)找到点和多边形之间的最小大圆距离。 我当前的堆栈包括 fiona、shapely、g
将 boost::geometry::line_interpolate 与 boost::geometry::srs::spheroid 结合使用,我正在计算沿最短距离的大圆导航点2个地理点。下面的代
如何在 JavaFX 中填充具有线性渐变(如 2d 圆)的 3D 球体?我使用 JavaFX Scene Builder。 最佳答案 正如@mohsenmadi 所指出的,漫反射颜色不允许您使用一种颜
我想使用 Python PyOpenGL 生成三个球体的场景。两个在有颜色的一侧(红色和绿色)。中间一个上面有任何纹理(砖 block 纹理实际上是与代码位于同一目录中的方形 jpg 文件)。 到目前
我从不同网格变量中的 .x 文件加载多个网格。现在我想计算我加载的所有网格(以及正在显示的网格)的包围球请指导我如何实现这一目标。可以将 VertexBuffers 附加到一个变量中并使用它计算 bo
我正在尝试用“粒子”(由 3D XYZ 向量表示)以最佳方式填充 3D 球形体积,这些粒子需要彼此保持特定距离,同时尽量减少它们之间存在的自由空间量. 但有一个问题 - 粒子本身可能会落在球形体积的边
我想创建一个球体,实际上是一个地球仪。但我似乎找不到任何有关如何处理球体的顶点和索引以及如何设置它们的有用信息。你们中的任何人都可以引导我走上正确的轨道,也许给我一些示例代码或指向教程的链接吗? 最佳
我终于手动画了一个球体:) 我希望我的球体是红色的,但轮廓是绿色的: 为了实现这一点,我做了以下事情。我用红色画了一个实心球体,然后我画了同一个球体,但线框和绿色。当我打开 DEPTH_TEST 时,
我想在 HTML 5.0 Canvas 中绘制 3D 球或球体。我想了解有关如何绘制 3D 球体的算法。谁可以与我分享这个? 最佳答案 您将需要为一个球体建模,并让它具有不同的颜色,以便在它旋转时您可
我正在尝试使用 webGL 构建 3D 太阳系。 我让所有恒星按照应有的方式绕太阳旋转,并且我希望它们也绕自己的 Y 轴旋转。 我怎样才能添加它?我尝试过: mat4.rotate(mvMatrix,
我有二维彩色图像。所有彩色点都位于此矩形图像中心的圆形区域内,圆圈外的所有点都是黑色的(我从鱼眼相机获得这些矩形图像)。我知道这个圆心的坐标和它的半径。 我需要将所有彩色点从 2D 图像上的圆形区域移
我正在用球体上的粒子进行 Metropolis Monte Carlo 模拟,并有一个关于给定时间步长内随机运动的问题。 我知道要在球体上获得均匀分布的随机点开始,使用最简单的方法是不够的(使用恒定
我想让球体向前移动一定的厘米,但到目前为止我还没有设法让任何东西正常工作这是我现在的代码: EditText distanceText = (EditText) findViewById(R.id.d
我想仅使用 Canvas 制作一个旋转对象(球体、盒子等)。但我找不到教程。如果您看到某个地方或解释如何做,请提供帮助。 像这样example ,仅无任何效果 最佳答案 希望你喜欢数学。如果您愿意编写
使用 GL_TRIANGLES 在 OpenGL ES 2.0 中绘制纹理球体的最简单方法是什么? 我特别想知道如何计算顶点。 最佳答案 有多种方法可以对球体进行三角测量。受欢迎的,不太受欢迎的,好的
我有一个关于在 HTML5/Canvas/Javascript 中伪造 3d 的问题... 基本上,我在 上绘制了一个二维图像使用 drawImage() . 我想做的是绘制图像,然后置换球体上的纹
我在 OpenGL ES 中绘制行星,遇到了一些有趣的性能问题。普遍的问题是:如何最好地在球体上渲染“非常详细”的纹理? (球体是有保证的;我对球体特定的优化很感兴趣) 基本案例: 窗口大约是。 20
对于我的论文项目,我使用 DataArts WebGL Globe 来开发一个网页,该网页将在触摸显示器上的展览中使用。作为监视器触摸,我需要使地球可点击以选择单个国家并打开弹出窗口并突出显示选定的国
我是一名优秀的程序员,十分优秀!