垂直轮播渲染脚本

发布于 2024-12-29 08:58:42 字数 1346 浏览 1 评论 0原文

我需要有关 CarouselExample 的一些帮助,可以使用此 链接。我想让它垂直旋转。我在 .rs 文件中找到了一个名为 getMatrixForCard 的方法,其中完成了卡片矩阵的转换。方法如下:

static bool getMatrixForCard(rs_matrix4x4* matrix, int i, bool enableSway, bool   
enableCardMatrix)
{
float theta = cardPosition(i);
float swayAngle = getSwayAngleForVelocity(velocity, enableSway);
rsMatrixRotate(matrix, degrees(theta), 0, 1, 0);
rsMatrixTranslate(matrix, radius, getVerticalOffsetForCard(i), 0); 
/* rsMatrixTranslate(matrix, 0, radius, 0);*/
float rotation = cardRotation + swayAngle;
if (!cardsFaceTangent) {
  rotation -= theta;
}
rsMatrixRotate(matrix, degrees(rotation), 0, 1, 0);
bool stillAnimating = false;
if (i == animatedSelection) {
    float3 scale;
    stillAnimating = getAnimatedScaleForSelected(&scale);
    rsMatrixScale(matrix, scale.x, scale.y, scale.z);
}
// TODO(jshuma): Instead of ignoring this matrix for the detail texture, use card 
bounding box
if (enableCardMatrix) {
    rsMatrixLoadMultiply(matrix, matrix, &cards[i].matrix);
}
return stillAnimating;
}

所以我猜想从这一行更改 x 和 y 的值可以使其工作。

rsMatrixTranslate(matrix, radius, getVerticalOffsetForCard(i), 0); 

但事实并非如此。如果有人检查过这个例子并且知道如何帮助我并使旋转木马垂直,我将不胜感激。

I need some help with the CarouselExample that can be checked out using this link. I want to make it spin vertically. I found a method in the .rs file called getMatrixForCard where the transformations on the matrix of the cards is done. Here is the method:

static bool getMatrixForCard(rs_matrix4x4* matrix, int i, bool enableSway, bool   
enableCardMatrix)
{
float theta = cardPosition(i);
float swayAngle = getSwayAngleForVelocity(velocity, enableSway);
rsMatrixRotate(matrix, degrees(theta), 0, 1, 0);
rsMatrixTranslate(matrix, radius, getVerticalOffsetForCard(i), 0); 
/* rsMatrixTranslate(matrix, 0, radius, 0);*/
float rotation = cardRotation + swayAngle;
if (!cardsFaceTangent) {
  rotation -= theta;
}
rsMatrixRotate(matrix, degrees(rotation), 0, 1, 0);
bool stillAnimating = false;
if (i == animatedSelection) {
    float3 scale;
    stillAnimating = getAnimatedScaleForSelected(&scale);
    rsMatrixScale(matrix, scale.x, scale.y, scale.z);
}
// TODO(jshuma): Instead of ignoring this matrix for the detail texture, use card 
bounding box
if (enableCardMatrix) {
    rsMatrixLoadMultiply(matrix, matrix, &cards[i].matrix);
}
return stillAnimating;
}

So i guessed that changing the values of x with y from this line, would make it work.

rsMatrixTranslate(matrix, radius, getVerticalOffsetForCard(i), 0); 

But it does not. Please if someone has checked this example and knows how to help me and make the carousel vertical, i would appreciate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月如刀 2025-01-05 08:58:42

您不需要更改此函数,您需要更改

carousel.rs 文件中的其他一些参数,将

static const float3 cardVertices[4] = {
        { -1.0, -1.0, 0.0 },
        { 1.0, -1.0, 0.0 },
        { 1.0, 1.0, 0.0 },
        {-1.0, 1.0, 0.0 }
};
// Default camera
static PerspectiveCamera camera = {
        {2,2,2}, // from
        {0,0,0}, // at
        {0,1,0}, // up
        25.0f,   // field of view
        1.0f,    // aspect
        0.1f,    // near
        100.0f   // far
};

static const float3 cardVertices[4] = {
        { 0.0, -1.0, -1.0 },
        { 0.0, -1.0, 1.0 },
        { 0.0, 1.0, 1.0 },
        { 0.0, 1.0, -1.0 }
};

static PerspectiveCamera camera = {
        {2,2,2}, // from
        {0,0,0}, // at
        {0,1,0}, // up
        40.0f,   // field of view
        1.0f,    // aspect
        0.1f,    // near
        100.0f   // far
};

CarouselTestActivity.java

private static final int CARD_SLOTS = 56;

和 更改为

private static final int CARD_SLOTS = 30;

和将 onCreate() 更改为如下

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.carousel_test);
    mView = (CarouselView) findViewById(R.id.carousel);
    mView.getHolder().setFormat(PixelFormat.RGBA_8888);
    mPaint.setColor(0xffffffff);
    final Resources res = getResources();

    mHelper = new LocalCarouselViewHelper(this);
    mHelper.setCarouselView(mView);
    mView.setSlotCount(CARD_SLOTS);
    mView.createCards(INCREMENTAL_ADD ? 1: TOTAL_CARDS);
    mView.setVisibleSlots(SLOTS_VISIBLE);
    mBorder = BitmapFactory.decodeResource(res, R.drawable.border);
    mView.setDefaultBitmap(mBorder);
    mView.setLoadingBitmap(mBorder);
    mView.setBackgroundColor(0.25f, 0.25f, 0.5f, 0.5f);
    mView.setRezInCardCount(3.0f);
    mView.setFadeInDuration(250);
    mView.setVisibleDetails(VISIBLE_DETAIL_COUNT);
    mView.setDragModel(CarouselView.DRAG_MODEL_CYLINDER_INSIDE);

    // New settings
    mView.setStartAngle((float) -(11.7f*Math.PI / 10));
    mView.setVisibleDetails(6);
    mView.setRowCount(3);
    mView.setRadius(10f);
    float mEye[] = { 2f, 0f, 0f };
    float mAt[] = { 0.0f, 0.0f, 0.0f };
    float mUp[] = { 0.0f, 1.0f, 0.0f };
    mView.setLookAt(mEye, mAt, mUp);
    mView.setCardsFaceTangent(true);

    if (INCREMENTAL_ADD) {
        mView.postDelayed(mAddCardRunnable, 2000);
    }

    mGlossyOverlay = BitmapFactory.decodeResource(res, R.drawable.glossy_overlay);
}

输出将如下
垂直轮播

you don't need to change in this function, you need to change in some other params

in the carousel.rs file replace

static const float3 cardVertices[4] = {
        { -1.0, -1.0, 0.0 },
        { 1.0, -1.0, 0.0 },
        { 1.0, 1.0, 0.0 },
        {-1.0, 1.0, 0.0 }
};
// Default camera
static PerspectiveCamera camera = {
        {2,2,2}, // from
        {0,0,0}, // at
        {0,1,0}, // up
        25.0f,   // field of view
        1.0f,    // aspect
        0.1f,    // near
        100.0f   // far
};

with

static const float3 cardVertices[4] = {
        { 0.0, -1.0, -1.0 },
        { 0.0, -1.0, 1.0 },
        { 0.0, 1.0, 1.0 },
        { 0.0, 1.0, -1.0 }
};

static PerspectiveCamera camera = {
        {2,2,2}, // from
        {0,0,0}, // at
        {0,1,0}, // up
        40.0f,   // field of view
        1.0f,    // aspect
        0.1f,    // near
        100.0f   // far
};

and in the CarouselTestActivity.java change

private static final int CARD_SLOTS = 56;

to

private static final int CARD_SLOTS = 30;

and change onCreate() to be as follow

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.carousel_test);
    mView = (CarouselView) findViewById(R.id.carousel);
    mView.getHolder().setFormat(PixelFormat.RGBA_8888);
    mPaint.setColor(0xffffffff);
    final Resources res = getResources();

    mHelper = new LocalCarouselViewHelper(this);
    mHelper.setCarouselView(mView);
    mView.setSlotCount(CARD_SLOTS);
    mView.createCards(INCREMENTAL_ADD ? 1: TOTAL_CARDS);
    mView.setVisibleSlots(SLOTS_VISIBLE);
    mBorder = BitmapFactory.decodeResource(res, R.drawable.border);
    mView.setDefaultBitmap(mBorder);
    mView.setLoadingBitmap(mBorder);
    mView.setBackgroundColor(0.25f, 0.25f, 0.5f, 0.5f);
    mView.setRezInCardCount(3.0f);
    mView.setFadeInDuration(250);
    mView.setVisibleDetails(VISIBLE_DETAIL_COUNT);
    mView.setDragModel(CarouselView.DRAG_MODEL_CYLINDER_INSIDE);

    // New settings
    mView.setStartAngle((float) -(11.7f*Math.PI / 10));
    mView.setVisibleDetails(6);
    mView.setRowCount(3);
    mView.setRadius(10f);
    float mEye[] = { 2f, 0f, 0f };
    float mAt[] = { 0.0f, 0.0f, 0.0f };
    float mUp[] = { 0.0f, 1.0f, 0.0f };
    mView.setLookAt(mEye, mAt, mUp);
    mView.setCardsFaceTangent(true);

    if (INCREMENTAL_ADD) {
        mView.postDelayed(mAddCardRunnable, 2000);
    }

    mGlossyOverlay = BitmapFactory.decodeResource(res, R.drawable.glossy_overlay);
}

the output will be as follow
Vertical Carousel

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文