📄 sprite3d.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN""http://www.w3.org/TR/REC-html40/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc on Thu Nov 27 13:54:36 EET 2003 -->
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>
Sprite3D (Mobile 3D Graphics API (M3G))
</TITLE>
<META NAME="keywords" CONTENT="javax.microedition.m3g.Sprite3D,Sprite3D class">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
</HEAD>
<SCRIPT>
function asd()
{
parent.document.title="Sprite3D (Mobile 3D Graphics API (M3G))";
}
</SCRIPT>
<BODY BGCOLOR="white" onload="asd();">
<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_top"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/Sprite3D.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
<EM><B>Nov 19, 2003</B></EM></EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../javax/microedition/m3g/SkinnedMesh.html"><B>PREV CLASS</B></A>
<A HREF="../../../javax/microedition/m3g/Texture2D.html"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html" TARGET="_top"><B>FRAMES</B></A>
<A HREF="Sprite3D.html" TARGET="_top"><B>NO FRAMES</B></A>
<SCRIPT> <!-- if(window==top) { document.writeln('<A HREF="../../../allclasses-noframe.html" TARGET=""><B>All Classes</B></A>'); } //--></SCRIPT><NOSCRIPT><A HREF="../../../allclasses-noframe.html" TARGET=""><B>All Classes</B></A></NOSCRIPT></FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY: NESTED | <A HREF="#fields_inherited_from_class_javax.microedition.m3g.Node">FIELD</A> | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
javax.microedition.m3g</FONT>
<BR>
Class Sprite3D</H2>
<PRE>
java.lang.Object
|
+--<A HREF="../../../javax/microedition/m3g/Object3D.html">javax.microedition.m3g.Object3D</A>
|
+--<A HREF="../../../javax/microedition/m3g/Transformable.html">javax.microedition.m3g.Transformable</A>
|
+--<A HREF="../../../javax/microedition/m3g/Node.html">javax.microedition.m3g.Node</A>
|
+--<B>javax.microedition.m3g.Sprite3D</B>
</PRE>
<HR>
<DL>
<DT>public class <B>Sprite3D</B><DT>extends <A HREF="../../../javax/microedition/m3g/Node.html">Node</A></DL>
<P>
<p>A scene graph node that represents a 2-dimensional image with a 3Dposition.</p><p>Sprite3D is a fast, but functionally restricted alternative totextured geometry. A Sprite3D is rendered as a screen-alignedrectangular array of pixels with a constant depth. The apparent sizeof a sprite may be specified directly in pixels (an unscaled sprite)or indirectly using the transformation from the Sprite3D node to thecamera space (a scaled sprite).</p><p>The structure of a Sprite3D object is shown in the figure below.</p><center><img src="./doc-files/Sprite3D-components.png"/></center><h3>Sprite image data</h3><p>The sprite image is stored as a reference to an Image2D. The imagemay be in any of the formats defined in Image2D. The width and heightof the image are not limited in any way; in particular, they need notbe powers of two. However, there is an implementation defined maximumsize for the crop rectangle (the area of the sprite that is actuallydisplayed). This can be queried with <A HREF="../../../javax/microedition/m3g/Graphics3D.html#getProperties()"><CODE>getProperties</CODE></A>.</p><p>The displayed sprite image can be mirrored with respect to the Xand/or Y axes by specifying a crop rectangle with a negative widthand/or height, respectively.</p><p>If the referenced Image2D is mutable and is modified while it isbound to a Sprite3D, or a new Image2D is bound as the sprite image, themodifications are immediately reflected in the Sprite3D. Be aware,however, that changing or updating the sprite image may triggertime-consuming operations.</p><h3>Sprite positioning and scaling</h3><p>The position of a sprite on screen is determined by projecting theorigin of its coordinate system to screen coordinates. The resulting2D position is used as the center of the displayed pixel array. Ifthis causes any part of the sprite to be placed off screen, then thesprite is clipped to the visible portion of the viewport as usual(refer to Graphics3D).</p><p>The depth value of a sprite is constant across the image, and is thedepth of the origin of the Sprite3D coordinate system.</p><p>The width and height of an <i>unscaled</i> sprite on screen are measuredin pixels, and they are equal to the (absolute) width and height of the croprectangle. Recall that the crop rectangle dimensions may be negative to flipthe pixels; this has no effect on the size of the sprite.</p><p>The width and height of a <i>scaled</i> sprite on screen are computedbasically as if the sprite were a rectangle with unit-length sides, lyingon the XY plane of its local coordinate system and centered at its origin.See the Implementation guidelines below for the details.</p><p>Because a sprite is always displayed as a screen-aligned rectangle,the effects of other than rigid-body transformations on sprites maynot be immediately intuitive, even though they are well-defined. It isadvised that, for example, non-uniform scaling and skewing be avoidedin sprite modelview matrices. Similarly, oblique projections should beused with caution when sprites are present in the displayed scene.</p><h3>Sprite rendering attributes</h3><p>The rendering attributes for a Sprite3D are determined by itsAppearance, as is the case with Mesh objects. There are a number ofproperties in Appearance, however, that do not have a meaningfulinterpretation in this context. Thus, only the CompositingMode and Fogcomponents and the layer index are taken into account when rendering asprite. The rest of the components are ignored. This implies, inparticular, that lighting does not apply for sprites.</p><p>Nearly all properties and methods inherited from Node areapplicable for sprites also. The only property that is ignoredwhen rendering is the alpha factor.</p><h3>Sprite picking</h3><p>Only scaled sprites can be picked. This is because the dimensions ofan unscaled sprite are only defined in screen space, that is, after theviewport transformation. Since the viewport parameters are not availableto the pick method, the dimensions of an unscaled sprite can not becomputed.</p><p>Picking of scaled sprites is analogous to how they are rendered.Picking is done in normalized device coordinates (after projection,before viewport transformation), where the position, depth value anddimensions of scaled sprites are well defined. See the Implementationguidelines for how to calculate these.</p><p>Since the sprite size calculation requires a Camera, sprites areonly pickable through the viewing plane, not from an arbitraryposition in the scene. That is, of the two <code>pick</code> variantsin Group, only the one that takes in a Camera as a parameter can beused in sprite picking. The other variant simply ignores all spritenodes.</p><p>If a sprite is intersected by the pick ray, the pixel in the spriteimage at the intersection point will be further tested for transparency.If the pixel is fully transparent, the sprite is not picked and the pickray will continue towards objects that are further away. If the pixel isnot fully transparent, the sprite is picked. A pixel is defined to befully transparent if and only if it fails the alpha test (see <A HREF="../../../javax/microedition/m3g/CompositingMode.html#setAlphaThreshold(float)"><CODE>CompositingMode.setAlphaThreshold(float)</CODE></A>).</p><h3>Implementation guidelines</h3><p>Sprites do not provide any functionality that would not be availableotherwise; they can always be substituted with textured meshes. However,the existence of the sprite primitive acts as a signal to the rendererthat a very specific subset of functionality is required. This allows therendering pipeline to avoid the overhead of transforming and lighting fullgeometry. It also allows the rasterizer to select an optimized drawingroutine to place the pixels on the screen, without the potentially complexinterpolation of parameters across the rectangle. This can be used to makesprites very much faster than textured meshes (especially in software)which in turn increases the richness of content that can be offered atthe low end.</p><h4>Implementing with textures</h4><p>Sprite3D can be implemented with textured rectangles. The restrictionon the maximum crop rectangle size is in place because otherwiseimplementations using this method would be forced to downsample largercrop rectangles to the maximum texture size; an expensive operation.</p><p>When implementing unscaled sprites with texture mapping, care shouldbe taken that rounding errors or similar do not yield unwelcome artifacts,such as pixel columns appearing and disappearing depending on the screenposition of the sprite. This is particularly important for text labels.</p><p>Filtering of scaled sprites can be implemented with the simple nearestneighbor algorithm, but implementations are free to apply more sophisticatedschemes, such as mipmapping. No application control over the filteringbehavior is provided, however; if that is required, textured rectanglescan be used instead.</p><h4>Computing the position and size</h4><p>The position of a sprite on the viewport is simply the projectedlocation of the Sprite3D node's origin. Similarly, the depth of thesprite is the projected depth of the origin.</p><p>The size of a sprite, in pixels, depends on whether the sprite isscaled or not. An unscaled sprite is the same size as its croprectangle. Calculating the size of a scaled sprite is slightly morecomplicated. In principle, it only involves projecting the Sprite3Dnode's X and Y axes into screen space and computing their length,but to make the calculation well defined under arbitrary transformations,a few additional steps are required. The exact formula is given below.</p><p>Let us define <b>M</b> and <b>P</b> as the current modelview andprojection matrices. The modelview matrix <b>M</b> is the concatenatedtransformation from the Sprite3D node into camera space (taking intoaccount all of the transformation components of the Sprite3D, includingthe user-settable static matrix), and <b>P</b> is the projectionmatrix of the current camera.</p><p>Let us first transform the origin and two reference points,corresponding to the X and Y axes, from the Sprite3D node'scoordinate system into camera space:</p><blockquote><b>o</b>' = <b>M</b> (0, 0, 0, 1)<sup>T</sup><br><b>x</b>' = <b>M</b> (1, 0, 0, 1)<sup>T</sup><br><b>y</b>' = <b>M</b> (0, 1, 0, 1)<sup>T</sup></blockquote><p>We then compute the distances from the origin to the X and Yreference points. If the bottom row of the modelview matrix isnot (0 0 0 1), the transformed points may have W values differentfrom each other. The points are thus brought into an equal scale
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -