Calculating vertex normals for an IndexedTriangleStripArray

Hi,
I'm trying to calculate the vertex normals to an IndexedTriangleStripArray, and I can't seem to get it right (Checked against a TriangleStripArray that I generated normals for using NormalGenerator). Basically, i'm generating normals for all of the surfaces that a vertex touches and then taking the average.
I do so by getting a center point (the vertex for which i'm calculating the normal), and all the points surrounding it (see comment above code below), out of a float array of coordinates and creating vectors and then cross producting them. I can't really see what I'm doing wrong. Might be because I've been staring at this for too long. Anyways, any help would be really appreciated.
oh, btw.. i need to use an IndexedTriangleStripArray, so I can't go through GeometryInfo to generate normals.
thanks alot,
nikolai
     * b-c-d
     * a-C-e
     * h-g-f
     *_w -> width of elevation grid
    public void setUpNormals(int[] stripcount)
        _normals = new float[_coords.length];
        float[] vecA = new float[3];
        float[] vecB = new float[3];
        float[] vecC = new float[3];
        float[] vecD = new float[3];
        float[] vecE = new float[3];
        float[] vecF = new float[3];
        float[] vecG = new float[3];
        float[] vecH = new float[3];
        float[] normAB;
        float[] normBC;
        float[] normCD;
        float[] normDE;
        float[] normEF;
        float[] normFG;
        float[] normGH;
        float[] normHA;
        float[] normal = new float[3];
        for(int i = 0; i < _coords.length/3; i++)
            int center = i*3;
            int a = center - 3;
            int b = a - _w*3;
            int c = center - _w*3;
            int d = c + 3;
            int e = center + 3;
            int f = e + _w*3;
            int g = center + _w*3;
            int h = g - 3;
            int row = (center/3)/(_w);
            int col = (center/3)%_w;
            if (col > 0)
                vecA[0] = _coords[a] - _coords[center];
                vecA[1] = _coords[a+1] - _coords[center+1];
                vecA[2] = _coords[a+2] - _coords[center+2];
                if (row>0)
                    vecB[0] = _coords[b] - _coords[center];
                    vecB[1] = _coords[b+1] - _coords[center+1];
                    vecB[2] = _coords[b+2] - _coords[center+2];
                if (row < _w - 1)
                    vecH[0] = _coords[h] - _coords[center];
                    vecH[1] = _coords[h+1] - _coords[center+1];
                    vecH[2] = _coords[h+2] - _coords[center+2];
            else
                vecA = new float[3];
                vecB = new float[3];
                vecH = new float[3];
            if (row>0)
                //vecB already initialized if its to be involved
                vecC[0] = _coords[c] - _coords[center];
                vecC[1] = _coords[c+1] - _coords[center+1];
                vecC[2] = _coords[c+2] - _coords[center+2];
                if (col < _w - 1){
                    vecD[0] = _coords[d] - _coords[center];
                    vecD[1] = _coords[d+1] - _coords[center+1];
                    vecD[2] = _coords[d+2] - _coords[center+2];
            else
                vecB = new float[3];
                vecC = new float[3];
                vecD = new float[3];
            if (col < _w - 1)
                //vecD already initialized
                vecE[0] = _coords[e] - _coords[center];
                vecE[1] = _coords[e+1] - _coords[center+1];
                vecE[2] = _coords[e+2] - _coords[center+2];
                if (row < _w - 1)
                    vecF[0] = _coords[f] - _coords[center];
                    vecF[1] = _coords[f+1] - _coords[center+1];
                    vecF[2] = _coords[f+2] - _coords[center+2];
            else
                vecD = new float[3];
                vecE = new float[3];
                vecF = new float[3];
            if (row < _w - 1)
                //vecF already initialized
                vecG[0] = _coords[g] - _coords[center];
                vecG[1] = _coords[g+1] - _coords[center+1];
                vecG[2] = _coords[g+2] - _coords[center+2];
                //vecH already initialized
            else
                vecF = new float[3];
                vecG = new float[3];
                vecH = new float[3];
            normAB = getNormal(vecA, vecB);
            normBC = getNormal(vecB, vecC);
            normCD = getNormal(vecC, vecD);
            normDE = getNormal(vecD, vecE);
            normEF = getNormal(vecE, vecF);
            normFG = getNormal(vecF, vecG);
            normGH = getNormal(vecG, vecH);
            normHA = getNormal(vecH, vecA);
            normal[0] = normAB[0]+ normBC[0] + normCD[0] + normDE[0] + normEF[0] + normFG[0] + normGH[0] + normHA[0];
            normal[1] = normAB[1]+ normBC[1] + normCD[1] + normDE[1] + normEF[1] + normFG[1] + normGH[1] + normHA[1];
            normal[2] = normAB[2]+ normBC[2] + normCD[2] + normDE[2] + normEF[2] + normFG[2] + normGH[2] + normHA[2];
            float magnitude = (float) Math.sqrt(normal[0]*normal[0] + normal[1]*normal[1] + normal[2]*normal[2]);
            normal[0]/=magnitude;
            normal[1]/=magnitude;
            normal[2]/=magnitude;
            _normals[center] = normal[0];
            _normals[center + 1] = normal[1];
            _normals[center + 2] = normal[2];
        return;
    }

Hi Greg,
Its simple :-)
Set the TriangleArray back to COLOR_3 (Specifies this vertex array contains colors without transparency); or it could even be COLOR_4.
Then, attach Appearance / ColoringAttributes / Material / TransparencyAttributes as shown below:
          Appearance a = new Appearance();
          PolygonAttributes pa = new PolygonAttributes( );
          pa.setPolygonMode( PolygonAttributes.POLYGON_FILL );
          pa.setCullFace( PolygonAttributes.CULL_NONE );
          a.setPolygonAttributes( pa );
          ColoringAttributes ca = new ColoringAttributes(0.4f, 1.0f, 0.6f, ColoringAttributes.SHADE_GOURAUD);
          a.setColoringAttributes( ca );
          Material mat = new Material();
          mat.setAmbientColor(0.6f, 0.6f, 0.1f);
          mat.setDiffuseColor(0.6f, 0.3f, 0.0f);
          mat.setEmissiveColor(0.3f, 0.3f, 0.3f);
          mat.setSpecularColor(1.0f, 1.0f, 1.0f);
          mat.setShininess(120.0f);
          a.setMaterial(mat);
          TransparencyAttributes ta = new TransparencyAttributes(1, 0.5f); // this sets the transparency
          ta.setTransparencyMode(ta.BLENDED);
          a.setTransparencyAttributes(ta);I hope this helps :-)
Cool :)
Ravi

Similar Messages

  • Model Binding and Calculated Field Syntax for "class" Attribute

    Hi,
    I tried to use the calculated field syntax from SAP UI5 to change the CSS class attribute of an element based on some model property, i.e., I wanted to change the class in the corresponding formatter function based on the currently bound value. However, my formatter function is not called. When I use the same syntax on a text attribute, it works.
    I also tried to use normal property binding, but it did not work on the class attribute either (it just put class="{property}" in the rendered HTML).
    Is there anything I missed or is it just not possible to use property binding and calculated field syntax for class attributes? Did anybody try something like this before?
    I think it is a standard use case to change the CSS class based on some model property. So, if anybody knows how to do that, could you give a short example?
    Best regards
    Svenja

    They have a class property. At least, I can do the following in an XML view:
    <Button
                  icon="sap-icon://add"
                  press="onButtonPress"
                  class="my-button-class" />
    I would expect the following to work as well, but for me it did not:
    <Button
                  icon="sap-icon://add"
                  press="onButtonPress"
                  class="{/customClass}" />
    This renders the following HTML (cropped to the important parts):
    <button type="button" class="sapMBtn {/customClass}">
    </button>
    It seems like the class attribute is something special although I don't see a reason why. Other HTML templating engines, for example, support things like that.

  • SSAS Multidimensional Time Intelligence YTD calculation showing BLANK for Date level

    Hi there,
    I am working with SSAS Multidimensional Cube, basically I have defined a Time Intelligence calculations for just YTD in the Cube, the calculation was created in the Calculations tab of the cube as follows:
    /*Year to Date*/
        [Dimension Dim Time].[Calendar Dimension Dim Time Calculations].[Year to Date],
    [Dimension Dim Time].[Year].Members, 
        [Dimension Dim Time].[Date].Members   
      =
      Aggregate(
                 { [Dimension Dim Time].[Calendar Dimension Dim Time Calculations].[Current Dimension Dim Time] } 
                 PeriodsToDate(
                                [Dimension Dim Time].[Calendar].[Year],
                                [Dimension Dim Time].[Calendar].CurrentMember
    My Calendar hierarchy is as follows:
    Year -> Quarter -> Month -> Week -> Date
    The problem I have is that when I am at Date level I am not getting the cumulative YTD value, instead I am just getting blank cells:
    Could anyone help me defining a Time Intelligence YTD calculation that works for all levels including the Date (highlighted in yellow above)?
    Thanks and best regards,
    Joss

    The only strange thing is the MDX script, I would have used this one instead (sse below) - but if this is not the issue, I would suggest you to isolate the issue in a simpler MDX script removing any other calculation.
    Also take a look at the DateTool solution for these calculations - I really don't like the wizard provided by the development environment, it has other issues but not something that should affect your calculation:
    http://www.sqlbi.com/articles/datetool-dimension-an-alternative-time-intelligence-implementation
    /*Year to Date*/
        [Dimension Dim Time].[Calendar Dimension Dim Time Calculations].[Year to Date],
        [Dimension Dim Time].[Calendar].Members, 
        [Dimension Dim Time].[Date].Members   
      =
      Aggregate(
                 { [Dimension Dim Time].[Calendar Dimension Dim Time Calculations].[Current Dimension Dim Time] } 
                 PeriodsToDate(
                                [Dimension Dim Time].[Calendar].[Year],
                                [Dimension Dim Time].[Calendar].CurrentMember
    Marco Russo http://ssasworkshop.com http://www.sqlbi.com http://sqlblog.com/blogs/marco_russo

  • HT201412 My cousin bought iPod touch 5th gen. Then it doesn't turned on. He charge it a charge icon appeared but after 30 mins still off . Is that normal for a brand new iPod touch? Please help me..

    My cousin bought iPod touch 5th gen. Then it doesn't turned on. He charge it a charge icon appeared but after 30 mins still off . Is that normal for a brand new iPod touch? Please help me..

    Not Charge
    - See:    
    iPod touch: Hardware troubleshooting
    iPhone and iPod touch: Charging the battery
    - Try another cable. The cable for 5G iPod (lightning connector) seems to be more prone to failure than the older cable.
    - If a 5G iPod      
    Iphone 5 lightning port charging problem - SOLUTION!
    - Try another charging source
    - Inspect the dock connector on the iPod for bent or missing contacts, foreign material, corroded contacts, broken, missing or cracked plastic.
    - Make an appointment at the Genius Bar of an Apple store.
      Apple Retail Store - Genius Bar
    and
    try:                                               
    - iOS: Not responding or does not turn on           
    - Also try DFU mode after try recovery mode
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    - If not successful and you can't fully turn the iOS device fully off, let the battery fully drain. After charging for an least an hour try the above again.
    - Try another cable       
    - Try on another computer                                                       
    - If still not successful that usually indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
      Apple Retail Store - Genius Bar                              

  • Is it normall for a Macbook Pro to overheat during  browsing web pages?

    DonAnan
    Is it normall for a Macbook Pro 13" retina 2 weeks old to overheat during browsing web pages ?
    i just brought a new MacBook Pro 13" Retina ( Dual Core i5 2.6GHz , 8GB Ram , 512GB Flash Storage ) and i notes that its really get OVERHEAT on the top right side of the keyboard and the fans work loudly when i brows web or play a game ( CSR Racing ) , it get heat that when i touch the top right side of the keyboard ( the aluminum body on top of the bower key exactly ) i cant keep my finger for morethan 10 or 15 second ..
    and the battery wont last for morethan 4 or 5 hours while it supposed to last for 9 hours according to Apple.
    so guys is this normal ?
    Thanks ,

    i've did some search on the same issue and it really seems like everyone have it , even thou at apple reseller showroom here in Doha-Qatar the sales man told me this a such issue in the retina macbooks and apple has admit it and you must take it to the service center and change it , while at the service center said a totally different things and that its fine to get heat ..
    in meanwhile my way back i pass by another apple reseller showroom and they clearly said if ur mack gets heat u must go and change it ...
    im really lost and i have no idea whats goin on here and whom should i listen to .. i hope someone from APPLE support will read this and reply us whats goin on ?     

  • Issue in Calculation schema determination for Scheduling Agreements

    Dear All,
      I am facing an issue in Calculation schema determination for Scheduling Agreements. The issue is -
    "Appropriate calculation schema is not being determined when a scheduling agreement is being created"
    The required settings which have been maintained are - The Calculation Schema (ZEIC31) has been created, Vendor Schema group has been created, Purchasing Organisation Schema group has been created, They both have been assigned to the Calculation schema in Schema determination, The Vendor Schema group has been assigned to the Vendor Master Record in master data creation.
    When I am creating the scheduling agreement, the system is by default choosing the calculation schema - RM0002. Thus I am not able to put the manual condition types which have been assigned in the calculation schema - ZEIC31.
    1> On what logic is the system picking that calculation schema?
    2> What settings can I do to make it pick that calculation schema only which has been assigned with POrg Sch Gp and Ve Sch Gp?
    Regards,
    Sudhanshu

    1> On what logic is the system picking that calculation schema?
    As per "Define Schema Determination" in spro Purchasing document should pick the Pricing Procedure .
    After creation of scheduling agreement have chacked your values in Scheduling agreement (Purchase ORG ,Schema grp in Vendor)
    2> What settings can I do to make it pick that calculation schema only which has been assigned with POrg Sch Gp and Ve Sch Gp?
    Check in Vendor mater is there any Plant specific Purcahsing data maintained.If it is plant specific Check purchasing data for that Plant.

  • Is it normal for files to go missing from an external hard drive?

    I've posted about this issue before but for slightly different reasons. I'm about to buy a new hard drive (the old one is full), probably I'll go for the exact same model, and I want to know if the problem I had described here has happened to Mac users.
    I use a Retina MBP with OS X 10.8.4 that also runs Windows 8 on boot camp. At the same time I have an Acer Aspire and what I used to do is download movies onto my external drive with my MBP in Mac - I would also rename the files in Mac - and then connect the drive to my Acer so I could access the movies there.
    One day I noticed that some of the files, after I had renamed and moved them to a new folder on the same partition, had gone missing. As I described in my old thread, it was a weird problem because those "missing" files would appear in Windows but not in Mac. But even in Windows when you could see the folders, they were all corrupted as the system indicated to me - the folders couldn't be accessed and the movies wouldn't play.
    Thankfully I haven't had this issue again but then I haven't dared to move any of my movies to a new folder either. Not since that incident. I'm pretty sure that I wouldn't have lost those movies and had them corrupted if I had kept them in their original location. Is it normal for files to go missing or be corrupted when you move them back and forth, especially when you use an external drive with one OS (Mac) and then switch to another (Windows)? I've always wondered if this was an issue. I never formatted the drive when I got it, I just plugged it in and used it. That was before I bought my MBP.
    I also was unable to delete those corrupted files/folders. Windows wouldn't let me and in Mac, they didn't even show up. I solved this eventually by using Disk Utility to repair the drive.
    Now I'm fine with letting my files stay put if that's what it takes to keep them safe and secure, but I'd be more comfortable if I can understand what went wrong all those months ago.
    The hard drive I have is this one from Samsung.

    Quick answer if you use iTunes' default preferences settings:  Copy the entire iTunes folder (and in doing so all its subfolders and files) intact to the other drive.  Open iTunes and immediately hold down the Option (alt) key (shift on Windows), then guide it to the iTunes Library.itl file in the moved iTunes folder.
    If you put the copied iTunes folder in the default location of Macintosh HD > Users > *User Name* > Music  then you don't even need to start with the option key held down, iTunes will automatically look for it there.  (Make sure there isn't anything already in the iTunes folder there that you want to keep since you will be replacing it with the one you are moving.)
    Longer answers if for any reason you do not think all library files are inside your iTunes folder (changed preferences settings at some point):
    iTunes: How to move [or copy] your music [library] to a new computer [or another drive] - http://support.apple.com/kb/HT4527 - a somewhat bewildering and not always easily understandable set of options.
    For the record there's this reference for iTunes 11 but it really doesn't strike me as having the specifics you need. iTunes 11 for Mac: Move your library to another computer - http://support.apple.com/kb/PH12168
    2011 ilounge article: Transferring your iTunes library - http://www.ilounge.com/index.php/articles/comments/moving-your-itunes-library-to -a-new-hard-drive/  - An article with good background information (similar to the links above), particularly if you are not sure your media files are all grouped for quick answer above. Unfortunately under the single term "transferring library" it describes two very different moves; relocating just your media (not  really transferring your library and not recommended unless you really need this configuration), and relocating media+database (really your whole "library").  Make sure you understand the difference before electing to move only media.

  • I dont know why the battery life of my iphone 4 is so low ! i really want to know how many hours i'll have if it's on standby. And how many hours if i use it normally for music and facebook (sometimes a little bit games)

    i dont know why the battery life of my iphone 4 is so low ! i really want to know how many hours i'll have if it's on standby. And how many hours if i use it normally for music and facebook (sometimes a little bit games) !!!

    to enhance your battery life, keep screen display to minimum, set screen lock automatically after 1 min, select internet notifications to off.

  • HT4060 Is it normal for someone to have general diffuculty charging an ipad?  I see the "not charging" message even when I am using the charger and cord that came in the original box, plugged into a wall socket directly.  It just seems to be exceedingly f

    Is it normal for someone to have general diffuculty charging an ipad?  I see the "not charging" message even when I am using the charger and cord that came in the original box, plugged into a wall socket directly.  It is normal for me to plug it in overnight and to see no charge whatsoever the next day.  I have never had so much trouble using a friggin charger in my life.  It just seems to be exceedingly finicky.  What am I missing?

    Charging your iPad should not be problematic. It should be an easy thing to do using the charger provided with your iPad connected to a known good wall outlet.
    The charging problem you are experiencing is most like caused by:
    1. A faulty charger
    2. A faulty cable
    3. A bad wall outlet
    4. A problem in the iPad.
    The first three of these are easiest to eliminate. Try a for ends charger and cable. Make absolutely sure your outlet is good. Try other outlets.
    If the charger, cable and outlet a proven to be good then the problem lies in the iPad.
    Make an appointment at an Apple Store to have your device examined by a technician. Or contact Apple Support.

  • Import Items Request remain in Status Pending Normal For a Long Period

    Hi,
    Import Items Concurrent Requests Remain in Status Pending Normal For a Long Period(30 minutes) Before Running.
    It is actually completing within 10 minutes after pending normal for 30 minutes.
    This problem is happening only with Import Items concurrent request, Other request are running as soon as they started.
    My Application version: 12.1.3
    Database Version:11.1.0.7
    My Standard Manager details Processes=16 Sleep Time=10 Cache=40
    Please correct, If there is need to change Standard Manager configuration...
    Plz reply soon.
    Regards,
    Alig

    Alig,
    Standard Manager is running this request, Import Item program request after the completion, creating Item categories for this it is taking time, that is the reason another import items request is waiting for the Item categories program to be completed.You need to find out why the "Item Categories" takes that long to complete.
    Do you have the statistics up to date?
    Enable trace as per these docs to find out why the request takes that long.
    How to Set a Trace with Bind and Waits from the Concurrent Request Form [ID 601647.1]
    How To Trace a Concurrent Request And Generate TKPROF File [ID 453527.1]
    Thanks,
    Hussein

  • Is it normal for JPWR to .....

    Is it normal for power connector JPWR, "the JPWR 12v power connector is used to provide power to the PCIEX16 graphics card" to output power?  Without being connected to the Power supply, this 4 pin molex connector powers my case fan.

    It is my understanding that the user is concerned over it being able to supply power.
    It would and does concern me a little if mine was/is doing the same thing, tbh i ain't gonna try it.
    IF this 4 pin molex, which is supposed to accept power from PSU is actually outputting power and enough of it to power 8Cm or 12Cm fan then its getting power from the psu without the 4 pin molex being connected. Which is what i believe the user is concerned with.
    The electricity has to be going to that 4 pin from psu thru board trace etc.
    Someone with a better knowledge of how power is distributed around board will be able to tell you if this is indeed a potentially dangerous scenario, as i would kind of expect power to get to that 4 pin thru PCB, however i am unsure as i know nothing about the flow of electricity thru a mainboard other than the obvious
    So on other words should this 4 pin that is supposed to accept power, be actually outputting power  , EG if you plug the 4 pin from psu into this is it accepting power and outputting power back to the PSU thru the 4 pin connector ?

  • Is It Normal For iTunes to freeze just before it finished syncing?

    I was just wondering is it normal for itunes to freeze and close unexpectedly or is there something wrong, and if there is can u help me?

    imvincent123 wrote:
    I was just wondering is it normal for itunes to freeze and close unexpectedly
    certainly not.
    or is there something wrong
    yes.
    and if there is can u help me?
    do you refer to your other post or is this a different issue ?

  • Is it normal for iPhone to get warm?

    Is it normal for iPhone to get hot?

    To get warm yes, depending on how you are using the phone.  Playing multi graphic games? yes.

  • Is it normal for apple tv to take up to 90 minutes to restore to factory settings?

    Is it normal for apple tv to take up to 90 minutes to restore to factory settings?

    Welcome to the Apple Community.
    No, that's not normal, should be no more than a couple of minutes. Updating afterwards may take a little longer since it depends on your network speeds.

  • Is it normal for Iphone 5 to overheat when using 3G?

    Hello,
    Is it normal for a new IPhone 5 to get overheated when using for 10mins 3G in searching something over Internet, watching a video on you tube or anything else that uses 3g? What could I do? Thanks

    Basic troubleshooting from the User's Guide is reset, restart, restore (first from backup then as new).  Try each of these in order until the issue is resolved.
    If the issue is still not resolved, then take it to Apple for evaluation and possible replacement.

Maybe you are looking for

  • Attachments not available when emailed to .me account on iPad.

    Photo attachments sent from another Ipad or Iphone or PC look like they are attached once recieved but show up as a question mark box or html code with no photo attached. I was able to view a photo that was imbedded in an email from my PC at work,but

  • Visual Composer 7.0.1 (EHP1) - Value Help only shows "Single Selection"

    I tried to add a value help to a field that allows multiple selections. However, when I used the wizard through "Add Value Help" drop-down menu, I can only see one proposed selection -  "Single selection". However this SAP help document (http://help.

  • NoShow FIOS Tech

    Twice I have had the FIOS tech scheduled to come out to my house and install FIOS in another room. TWICE he has not shown. The first time ( which I took vacation time off work for) the claim  was the order was not in the computer, even though I had a

  • EBS or Lockbox!

    Need bit of guidance, Please HELP. 1) Why would someone implement both EBS and Lockbox, when we know that EBS can also provide the incoming payment details and clearing of G/L and A/R entries. Is lockbox provides some additional benefits than in EBS.

  • 11g Release 2 install missing packages

    Hi, I'm trying to install 11g Release 2 on a CentOS (4.9) box, but the pre-req check shows that I'm missing the following packages (I had 9 to begin): gcc-3.4.6 (X86_64) gcc-c++-3.4.6(X86_64) libstdc++-devel-3.4.6 Tried to use the yum command "yum in