Skip to content

The 25 days of C++mas - December 25 - Happy C++mas!!!

This is the last of my blog posts for December and the 25 days of C++mas. Happy C++mas everyone.  I’ve created a FireMonkey 3D C++Builder application that contains 4 TSphere, a TLayer3D, 4 TLabel, 4 TTextureMaterialSource and TFloatAnimation components.  Each of the 3D spheres uses a FloatAnimation to change the Rotation Angle of each of the Spheres.  The TTextureMaterialSource components put bitmaps on each of the spheres.  This C++ application will run on 32-bit (Windows and Mac) and 64-bit (Windows) platforms.

To create the FireMonkey 3D application use the File | New | Fire Monkey Desktop Application - C++Builder menu item and when the application dialog box appears:

Place the TLayer3D, four TLabel,  four TSphere, four TFloatAnimation and four TTextureMaterialSource components on the form and associate one TFloatAnimation and one TTextureMaterialSource with each sphere. The TLayer3D allows you to put 2D components on a 3D form.  I set the Name property of each Sphere.  Your Structure View should look something the following:

Set the Text properties of each TLabel to your favorite holidays - I chose Christmas, Hanukkah, Kwanzaa and C++mas.  Set each FloatAnimation’s Duration, Enabled, PropertyName, StartValue and StopValue to change the RotationAngle.X or Rotation Angle.Y properties of the sphere (for the speed and motion you want for each sphere "ornament").

You have two choices to load textures into the TTextureMaterialSource components:

  • 1) You can load your favorite bitmaps/textures into each of the TextureMaterialSource components at design time - this can make your form files grow larger as the bitmaps will be encoded and become part of our executable.
  • 2) You cal load your favorite bitmaps/textures into each TextureMaterialSource at runtime using code. The form files and executables will be smaller but you will need to deploy the bitmap files along with your application.

Set each Sphere’s MaterialSource property to one of the TextureMaterialSource components.  You can view a FireMonkey form as text by right mouse click on the Form and choose "View as Text".  Here is a partial listing of the Form’s text representation so that you can see what properties and values I set for the Sphere and FloatAnimation components.  You will notice that the "View as Text" will only list property settings that are different from the "default" property values. For example - on the FloatAnimation1 property settings you will see a StopValue of 359 but no StartValue setting.  It is not included because StartValue has a default value of 0, which is the value I used so that the RotationAngle.Y will go from 0 to 359 degrees.

      object TreeSphere: TSphere
        Position.X = -6.828507900238037000
        Position.Y = 3.072811126708984000
        Width = 5.000000000000000000
        Height = 5.000000000000000000
        Depth = 5.000000000000000000
        MaterialSource = TreeTinselMaterialSource
        object FloatAnimation1: TFloatAnimation
          Enabled = True
          Duration = 4.000000000000000000
          Loop = True
          PropertyName = 'RotationAngle.Y'
          StopValue = 359.000000000000000000
        end
    
      object HannukahSphere: TSphere
        Position.X = 7.217988967895508000
        Position.Y = 2.063672065734863000
        RotationAngle.X = 20.000000000000000000
        RotationAngle.Y = 270.000000000000000000
        RotationAngle.Z = 330.000000000000000000
        Width = 5.000000000000000000
        Height = 5.000000000000000000
        Depth = 5.000000000000000000
        MaterialSource = HanukkahMaterialSource
       object FloatAnimation2: TFloatAnimation
          Enabled = True
          Duration = 4.000000000000000000
          Loop = True
          PropertyName = 'RotationAngle.Y'
          StopValue = 359.000000000000000000
        end
    
      object KwanzaaSphere: TSphere
        Position.X = 0.190251916646957400
        Position.Y = 6.073725700378418000
        RotationAngle.X = 158.064422607421900000
        RotationAngle.Y = 270.000000000000000000
        RotationAngle.Z = 200.000000000000000000
        Width = 6.000000000000000000
        Height = 6.000000000000000000
        Depth = 6.000000000000000000
        MaterialSource = KwanzaaTextureMaterialSource
        object FloatAnimation3: TFloatAnimation
          Enabled = True
          Duration = 4.000000000000000000
          Loop = True
          PropertyName = 'RotationAngle.Y'
          StartValue = 359.000000000000000000
        end
    
      object StroustrupSphere: TSphere
        Position.X = 0.131766766309738200
        Position.Y = -0.606817245483398400
        RotationAngle.Y = 270.000000000000000000
        Width = 5.000000000000000000
        Height = 5.000000000000000000
        Depth = 5.000000000000000000
        MaterialSource = StroustrupMaterialSource
        object FloatAnimation4: TFloatAnimation
          Enabled = True
          Duration = 10.000000000000000000
          Loop = True
          PropertyName = 'RotationAngle.Y'
          StartValue = 359.000000000000000000
        end

If you  load the texture bitmaps at design time (be careful about your form and executable size being larger depending on the texture sized), your form will look something like the following depending on which texture files or bitmaps you use in your C++Builder FireMonkey 3D application:

In my case, I chose to load the texture bitmaps (you can use whatever texture bitmaps you want to use, just change the filenames in the LoadFromFile function calls) at runtime in the Form’s OnCreate event handler:

    void __fastcall TForm3D1::Form3DCreate(TObject *Sender)
    {
    	TreeTinselMaterialSource->Texture->LoadFromFile("ChristmasTreeTextureOpryland.jpg");
    	StroustrupMaterialSource->Texture->LoadFromFile("10834_bjarne_stroustrup.jpg");
    	HanukkahMaterialSource->Texture->LoadFromFile("hanukkah-card.jpg");
    	KwanzaaTextureMaterialSource->Texture->LoadFromFile("kwanzaaTexture.jpg");
    }

These are the only lines of code added for this application.  Compile, Run and enjoy the application :)

You can download the Happy C++mas Texture Demo Project and video showing it running with my chosen texture bitmaps. The application is built with C++Builder XE3 update #1. Project with video is available at http://cc.embarcadero.com/item/29247.

That’s it for C++mas (but watch for my 31 C++ project videos in January)

That’s it.  I have created 25 blog posts in the 25 days of C++mas.  Thank you to everyone who sent emails and posted comments.

Stay tuned to my blog, next year (January 2013) when I will create 31 C++ videos in the 31 days of January focused on a wide variety of applications you can build with C++32 (Windows and Mac) and C++64 (Windows).

Watch/Download the C++Builder 64-bit Compiler Preview Video

Additional details about the 64-bit C++Builder compiler are available in the preview video.  Watch the C++ 64-bit compiler preview video on YouTube at http://www.youtube.com/watch?v=PwwMpBUoR6Y. You can also download the MP4 video file at http://cc.embarcadero.com/item/29197.  The preview video is 9 minutes long.

Try the C++Builder 64-bit compiler

The C++Builder XE3 and RAD Studio XE3 free trial downloads have been updated to include the new C++Builder 64-bit compiler.  Trial downloads are available at https://downloads.embarcadero.com/free/c_builder

Happy C++mas!

During the first 25 days of December leading up to Christmas, I will blog about the release of the C++Builder 64-bit compiler for Microsoft Windows and C++Builder XE3 support for building VCL and FireMonkey 2 applications.

Bad Behavior has blocked 4 access attempts in the last 7 days.

Close