summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-07-21 11:49:08 +0200
committerSven Gothel <[email protected]>2011-07-21 11:49:08 +0200
commit4aa66890176e9c2d8e648d6031c9491c3d625e07 (patch)
tree68256127a3e68313b127786a8c49eaefa9e7056e /src
parentdc4b259b6651bdc0cec0895bc74e26e504870c8e (diff)
Fix TestStructAccessorEndian
- StructAccessor uses byteOffset now (since 8b3057585930357bb16546f584d998953b084034) Fix linux armv7l eabi: - build.xml arm7 -> armv7 - all tests passes Adding NativeSizeAlignment-linux-armv7l_eabi from passing test OK: linux 32/64/armv7l, windows 32/64
Diffstat (limited to 'src')
-rw-r--r--src/junit/com/jogamp/common/nio/TestStructAccessorEndian.java13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/junit/com/jogamp/common/nio/TestStructAccessorEndian.java b/src/junit/com/jogamp/common/nio/TestStructAccessorEndian.java
index 8a20272..4a9173e 100644
--- a/src/junit/com/jogamp/common/nio/TestStructAccessorEndian.java
+++ b/src/junit/com/jogamp/common/nio/TestStructAccessorEndian.java
@@ -1,8 +1,9 @@
package com.jogamp.common.nio;
-import com.jogamp.common.nio.*;
import com.jogamp.common.os.*;
+import com.jogamp.gluegen.test.junit.generation.Test1p1JavaEmitter;
+import java.io.IOException;
import java.nio.*;
import org.junit.Assert;
@@ -28,13 +29,19 @@ public class TestStructAccessorEndian {
int i;
for(i=0; i<valuesSource.length; i++) {
- acc.setLongAt(i, valuesSource[i]);
+ acc.setLongAt(i*8, valuesSource[i]);
}
for(i=0; i<valuesSource.length; i++) {
- long v = acc.getLongAt(i);
+ long v = acc.getLongAt(i*8);
long t = valuesSource[i];
Assert.assertTrue("Value["+i+"] shall be 0x"+Long.toHexString(t)+", is: 0x"+Long.toHexString(v), t == v);
}
}
+
+ public static void main(String args[]) throws IOException {
+ String tstname = TestStructAccessorEndian.class.getName();
+ org.junit.runner.JUnitCore.main(tstname);
+ }
+
}
id='n185' href='#n185'>185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
/*
 * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 * - Redistribution of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * 
 * - Redistribution in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 * 
 * Neither the name of Sun Microsystems, Inc. or the names of
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * 
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
 * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR
 * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR
 * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
 * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
 * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
 * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 * 
 * You acknowledge that this software is not designed or intended for use
 * in the design, construction, operation or maintenance of any nuclear
 * facility.
 * 
 * Sun gratefully acknowledges that this software was originally authored
 * and developed by Kenneth Bradley Russell and Christopher John Kline.
 */

package demos.xtrans;

import java.awt.*;
import java.awt.geom.*;
import java.util.*;
import gleem.linalg.*;

/** A basic transition manager supporting animated scrolling, rotating
 * and fading of components.
 *
 * @author Kenneth Russell
 */

public class XTBasicTransitionManager implements XTTransitionManager {
  /** Indicates the style of the transition (either no motion,
      scrolling, or rotating). */
  public static class Style {
    private Style() {}
  }

  /** Indicates the component has no motion (scrolling or rotation) in
      its animation. */
  public static Style STYLE_NO_MOTION = new Style();

  /** Indicates the component is to be scrolled in to or out of
      place. */
  public static Style STYLE_SCROLL    = new Style();

  /** Indicates the component is to be rotated in to or out of
      place. */
  public static Style STYLE_ROTATE    = new Style();

  /** Indicates the direction of the transition if it contains any
      motion (either up, down, left, or right). */
  public static class Direction {
    private Direction() {}
  }

  /** Indicates the component's animation is from or toward the left,
      depending on whether the transition is an "in" or "out"
      transition. */
  public static Direction DIR_LEFT  = new Direction();

  /** Indicates the component's animation is from or toward the right,
      depending on whether the transition is an "in" or "out"
      transition. */
  public static Direction DIR_RIGHT = new Direction();

  /** Indicates the component's animation is in the upward
      direction. */
  public static Direction DIR_UP    = new Direction();

  /** Indicates the component's animation is in the downward
      direction. */
  public static Direction DIR_DOWN  = new Direction();

  private Style     nextTransitionStyle;
  private Direction nextTransitionDirection;
  private boolean   nextTransitionFade;

  private Random random;

  /** Sets the next transition to be used by this transition manager
      for either an "in" or an "out" transition. By default the
      transition manager selects random transitions from those
      available. */
  public void setNextTransition(Style style,
                                Direction direction,
                                boolean fade) {
    if (style == null) {
      throw new IllegalArgumentException("Must supply a style");
    }
    nextTransitionStyle     = style;
    nextTransitionDirection = direction;
    nextTransitionFade      = fade;
  }

  /** Creates an XTBasicTransition for the given component. By default
      this transition manager chooses a random transition from those
      available if one is not specified via {@link #setNextTransition
      setNextTransition}. */
  public XTTransition createTransitionForComponent(Component c,
                                                   boolean isAddition,
                                                   Rectangle   oglViewportOfDesktop,
                                                   Point       viewportOffsetFromOrigin,
                                                   Rectangle2D oglTexCoordsOnBackBuffer) {
    if (nextTransitionStyle == null) {
      chooseRandomTransition();
    }

    // Figure out the final positions of everything
    // Keep in mind that the Java2D origin is at the upper left and
    // the OpenGL origin is at the lower left
    Rectangle bounds = c.getBounds();
    int x = bounds.x;
    int y = bounds.y;
    int w = bounds.width;
    int h = bounds.height;
    float tx = (float) oglTexCoordsOnBackBuffer.getX();
    float ty = (float) oglTexCoordsOnBackBuffer.getY();
    float tw = (float) oglTexCoordsOnBackBuffer.getWidth();
    float th = (float) oglTexCoordsOnBackBuffer.getHeight();
    float vx = oglViewportOfDesktop.x;
    float vy = oglViewportOfDesktop.y;
    float vw = oglViewportOfDesktop.width;
    float vh = oglViewportOfDesktop.height;
    Quad3f verts = new Quad3f(new Vec3f(0,  0, 0),
                              new Vec3f(0, -h, 0),
                              new Vec3f(w, -h, 0),
                              new Vec3f(w,  0, 0));
    Quad2f texcoords = new Quad2f(new Vec2f(tx,      ty + th),
                                  new Vec2f(tx,      ty),
                                  new Vec2f(tx + tw, ty),
                                  new Vec2f(tx + tw, ty + th));

    XTBasicTransition trans = new XTBasicTransition();

    Vec3f translation = new Vec3f(x - viewportOffsetFromOrigin.x,
                                  vh - y - viewportOffsetFromOrigin.y,
                                  0);
    InterpolatedVec3f transInterp = new InterpolatedVec3f();
    transInterp.setStart(translation);
    transInterp.setEnd(translation);

    InterpolatedQuad3f quadInterp = new InterpolatedQuad3f();
    quadInterp.setStart(verts);
    quadInterp.setEnd(verts);

    InterpolatedQuad2f texInterp = new InterpolatedQuad2f();
    texInterp.setStart(texcoords);
    texInterp.setEnd(texcoords);

    trans.setTranslation(transInterp);
    trans.setVertices(quadInterp);
    trans.setTexCoords(texInterp);

    // Now decide how we are going to handle this transition
    Style     transitionStyle     = nextTransitionStyle;
    Direction transitionDirection = nextTransitionDirection;
    boolean   fade                = nextTransitionFade;
    nextTransitionStyle = null;
    nextTransitionDirection = null;
    nextTransitionFade = false;

    int[] vtIdxs = null;
    int[] ttIdxs = null;
    Vec3f rotAxis = null;
    Vec3f pivot = null;
    float startAngle = 0;
    float endAngle = 0;

    if (fade) {
      InterpolatedFloat alpha = new InterpolatedFloat();
      float start = (isAddition ? 0.0f : 1.0f);
      float end   = (isAddition ? 1.0f : 0.0f);
      alpha.setStart(start);
      alpha.setEnd(end);
      trans.setAlpha(alpha);
    }

    if (transitionDirection != null) {
      if (transitionStyle == STYLE_SCROLL) {
        if (transitionDirection == DIR_LEFT) {
          vtIdxs = new int[] { 3, 2, 2, 3 };
          ttIdxs = new int[] { 0, 1, 1, 0 };
        } else if (transitionDirection == DIR_RIGHT) {
          vtIdxs = new int[] { 0, 1, 1, 0 };
          ttIdxs = new int[] { 3, 2, 2, 3 };
        } else if (transitionDirection == DIR_UP) {
          vtIdxs = new int[] { 1, 1, 2, 2 };
          ttIdxs = new int[] { 0, 0, 3, 3 };
        } else {
          // DIR_DOWN
          vtIdxs = new int[] { 0, 0, 3, 3 };
          ttIdxs = new int[] { 1, 1, 2, 2 };
        }
      } else if (transitionStyle == STYLE_ROTATE) {
        if (transitionDirection == DIR_LEFT) {
          rotAxis = new Vec3f(0, 1, 0);
          pivot = new Vec3f();
          startAngle = -90;
          endAngle = 0;
        } else if (transitionDirection == DIR_RIGHT) {
          rotAxis = new Vec3f(0, 1, 0);
          pivot = new Vec3f(w, 0, 0);
          startAngle = 90;
          endAngle = 0;
        } else if (transitionDirection == DIR_UP) {
          rotAxis = new Vec3f(1, 0, 0);
          pivot = new Vec3f(0, -h, 0);
          startAngle = 90;
          endAngle = 0;
        } else {
          // DIR_DOWN
          rotAxis = new Vec3f(1, 0, 0);
          pivot = new Vec3f();
          startAngle = -90;
          endAngle = 0;
        }
      }
    }


    /*
    switch (transitionType) {
      case FADE:
      {
        InterpolatedFloat alpha = new InterpolatedFloat();
        float start = (isAddition ? 0.0f : 1.0f);
        float end   = (isAddition ? 1.0f : 0.0f);
        alpha.setStart(start);
        alpha.setEnd(end);
        trans.setAlpha(alpha);
        break;
      }
      case SCROLL_LEFT:
      {
        vtIdxs = new int[] { 3, 2, 2, 3 };
        ttIdxs = new int[] { 0, 1, 1, 0 };
        break;
      }
      case SCROLL_RIGHT:
      {
        vtIdxs = new int[] { 0, 1, 1, 0 };
        ttIdxs = new int[] { 3, 2, 2, 3 };
        break;
      }
      case SCROLL_UP:
      {
        vtIdxs = new int[] { 1, 1, 2, 2 };
        ttIdxs = new int[] { 0, 0, 3, 3 };
        break;
      }
      case SCROLL_DOWN:
      {
        vtIdxs = new int[] { 0, 0, 3, 3 };
        ttIdxs = new int[] { 1, 1, 2, 2 };
        break;
      }
      case ROTATE_LEFT:
      {
        rotAxis = new Vec3f(0, 1, 0);
        pivot = new Vec3f();
        startAngle = -90;
        endAngle = 0;
        break;
      }
      case ROTATE_RIGHT:
      {
        rotAxis = new Vec3f(0, 1, 0);
        //        pivot = translation.plus(new Vec3f(w, 0, 0));
        pivot = new Vec3f(w, 0, 0);
        startAngle = 90;
        endAngle = 0;
        break;
      }
      case ROTATE_UP:
      {
        rotAxis = new Vec3f(1, 0, 0);
        //        pivot = translation.plus(new Vec3f(0, -h, 0));
        pivot = new Vec3f(0, -h, 0);
        startAngle = 90;
        endAngle = 0;
        break;
      }
      case ROTATE_DOWN:
      {
        rotAxis = new Vec3f(1, 0, 0);
        pivot = new Vec3f();
        startAngle = -90;
        endAngle = 0;
        break;
      }
    }

    */

    if (vtIdxs != null) {
      if (isAddition) {
        quadInterp.setStart(new Quad3f(verts.getVec(vtIdxs[0]),
                                       verts.getVec(vtIdxs[1]),
                                       verts.getVec(vtIdxs[2]),
                                       verts.getVec(vtIdxs[3])));
        texInterp.setStart(new Quad2f(texcoords.getVec(ttIdxs[0]),
                                      texcoords.getVec(ttIdxs[1]),
                                      texcoords.getVec(ttIdxs[2]),
                                      texcoords.getVec(ttIdxs[3])));
      } else {
        // Note: swapping the vertex and texture indices happens to
        // have the correct effect
        int[] tmp = vtIdxs;
        vtIdxs = ttIdxs;
        ttIdxs = tmp;

        quadInterp.setEnd(new Quad3f(verts.getVec(vtIdxs[0]),
                                     verts.getVec(vtIdxs[1]),
                                     verts.getVec(vtIdxs[2]),
                                     verts.getVec(vtIdxs[3])));
        texInterp.setEnd(new Quad2f(texcoords.getVec(ttIdxs[0]),
                                    texcoords.getVec(ttIdxs[1]),
                                    texcoords.getVec(ttIdxs[2]),
                                    texcoords.getVec(ttIdxs[3])));
      }
    } else if (rotAxis != null) {
      if (!isAddition) {
        float tmp = endAngle;
        endAngle = -startAngle;
        startAngle = tmp;
      }

      trans.setPivotPoint(pivot);
      trans.setRotationAxis(rotAxis);
      InterpolatedFloat rotInterp = new InterpolatedFloat();
      rotInterp.setStart(startAngle);
      rotInterp.setEnd(endAngle);
      trans.setRotationAngle(rotInterp);
    }

    return trans;
  }

  /** Chooses a random transition from those available. */
  protected void chooseRandomTransition() {
    if (random == null) {
      random = new Random();
    }
    nextTransitionFade = random.nextBoolean();
    nextTransitionStyle = null;
    do {
      int style = random.nextInt(3);
      switch (style) {
        // Make no-motion transitions always use fades for effect
        // without biasing transitions toward no-motion transitions
        case 0:   if (nextTransitionFade) nextTransitionStyle = STYLE_NO_MOTION; break;
        case 1:   nextTransitionStyle = STYLE_SCROLL;                            break;
        default:  nextTransitionStyle = STYLE_ROTATE;                            break;
      }
    } while (nextTransitionStyle == null);
    int dir = random.nextInt(4);
    switch (dir) {
      case 0:   nextTransitionDirection = DIR_LEFT;  break;
      case 1:   nextTransitionDirection = DIR_RIGHT; break;
      case 2:   nextTransitionDirection = DIR_UP;    break;
      default:  nextTransitionDirection = DIR_DOWN;  break;
    }
  }
}