Android 垂直旋转木马渲染脚本

Android 垂直旋转木马渲染脚本,android,carousel,renderscript,Android,Carousel,Renderscript,我需要一些关于CarouseXample的帮助,可以使用这个来检查。我想让它垂直旋转。我在.rs文件中找到了一个名为getMatrixForCard的方法,在该文件中,卡的矩阵上的转换是在该方法中完成的。方法如下: static bool getMatrixForCard(rs_matrix4x4* matrix, int i, bool enableSway, bool enableCardMatrix) { float theta = cardPosition(i); float sw

我需要一些关于CarouseXample的帮助,可以使用这个来检查。我想让它垂直旋转。我在.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;
}
所以我猜,从这条直线上用y来改变x的值,会使它起作用

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

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

您不需要更改此函数,您需要更改其他一些参数

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
};

carouseltestativity.java中

private static final int CARD_SLOTS = 56;

并将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);
}
输出如下所示

我已经制作了垂直旋转木马,但非常感谢您的回复。回答我的renderscript问题的人不多。如果我有时间,我会检查一下。没有renderscript,你是怎么做到的???@Hakem,你在哪里找到3d旋转木马源的?我没有在/samples/android-11/RenderScript下看到它,就像上面说的那样。你可以在这个链接@Hakem中找到它,你能建议如何从左到右填充,而不是相反吗?另外,在纵向模式下,每一端的最后一列都被切断。你能详细说明一下你是如何完成垂直旋转木马的吗?
private static final int CARD_SLOTS = 30;
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);
}