IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

C# Placer des images sur les six face d'un cube


Sujet :

C#

  1. #1
    Nouveau Candidat au Club
    Inscrit en
    Mai 2007
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 5
    Points : 1
    Points
    1
    Par défaut C# Placer des images sur les six face d'un cube
    Bonjour,
    Je suis nouveau en C# et je voudrais savoir si vous auriez une technique pour placer des images sur un cube en C#. J'ai deja dessiné le cube mais je n'arrive pas à mettre les image dessus en fait mon cube tourne et je veux mettre la même image sur les 6 faces du cubes
    Merci pour votre aide

  2. #2
    Membre actif Avatar de Luffy49
    Profil pro
    Étudiant
    Inscrit en
    Mars 2007
    Messages
    399
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2007
    Messages : 399
    Points : 247
    Points
    247
    Par défaut
    Peut-tu nous donner le code du cube en question ?
    La connaissance n'est rien si elle n'est pas partagé

    Citation de Confucius :
    Ceux dont la connaissance est innée sont des hommes tout à fait supérieurs. Puis viennent ceux qui acquièrent cette connaissance par l'étude. Enfin, ceux qui, même dans la détresse, n'étudient pas : c'est le peuple.

  3. #3
    Membre confirmé Avatar de themadmax
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    446
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 446
    Points : 496
    Points
    496
    Par défaut
    Comment fait tu tourner ton cube ? En DirectX ?
    Ou tu as toi même codé un moteur 3D ? si oui il est possible d'appliquer des transformation matriciel au image pour faire un placage de texture.
    ________________________________________________
    http://bliquid.fr : Blog sur Android et l'Acer Liquid

  4. #4
    Nouveau Candidat au Club
    Inscrit en
    Mai 2007
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 5
    Points : 1
    Points
    1
    Par défaut Direct X
    Re
    Excusé mon retard je suis débordé en ce moment avec le C#.
    en effet j'utilise direct X. Avez vous une idée pour m'aider à avancer. Je vous met le code que j'ai recupéré sur internet et que j'ai modifé, il affiche un cube et je veux qu'il affiche 6 images différente sur chaque face du cube 3D. Le cube tourne sans cesse, je veux qu'il tourne en fonction de l'interaction du stylet avec l'ecran du mobile. exmple; Clic droit avec le stylet le cube tourne à droite et affiche la face suivante....

    Merci de me repondre le plus tot posssible j'ai une présentation demain

    Merci j'attend vos reponses.

    Voici le code:


    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Reflection;
    using Microsoft.WindowsMobile.DirectX;
    using Microsoft.WindowsMobile.DirectX.Direct3D;
    using System.Runtime.InteropServices;

    namespace ft.fr.cube
    {

    // The main application class
    public class Cube : Form
    {
    // Our global variables for this project
    Device device = null;
    VertexBuffer vertexBuffer = null;
    PresentParameters presentParams = new PresentParameters();
    Texture []texture = new Texture[6];
    int i = 6;
    int j = 500;
    // Class constructor
    public Cube()
    {
    // Set the caption
    // InitializeComponent();
    this.InitializeGraphics();
    this.creerTriangle();
    this.OnResetDevice(device, null);
    }


    // Prepares the rendering device
    public bool InitializeGraphics()
    {
    try
    {
    // We don't want to run fullscreen
    presentParams.Windowed = true;
    // Discard the frames
    presentParams.SwapEffect = SwapEffect.Discard;

    // Turn on a Depth stencil
    // presentParams.EnableAutoDepthStencil = true;
    // And the stencil format
    presentParams.AutoDepthStencilFormat = DepthFormat.D16;
    //Create a device
    this.device = new Device(0, DeviceType.Default, this,
    CreateFlags.None, presentParams);
    this.device.RenderState.Lighting = false;
    }
    catch (DirectXException e)
    {

    // Catch any errors and return a failure
    MessageBox.Show("Erreur divce construction"+e.StackTrace);
    return false;
    }
    return true;
    }

    // Called whenever the rendering device is created

    void creerTriangle()
    {

    try
    {
    // Now Create the VB

    // Get the device capabilities
    Pool vertexBufferPool;
    Caps caps;
    caps = this.device.DeviceCaps;

    if (caps.SurfaceCaps.SupportsVidVertexBuffer)
    vertexBufferPool = Pool.VideoMemory;
    else
    vertexBufferPool = Pool.SystemMemory;

    this.vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured),36, this.device,
    Usage.DoNotClip, CustomVertex.PositionNormalTextured.Format,
    vertexBufferPool);
    // Récupère le tableau de vertices du buffer.
    Array tmpArray = this.vertexBuffer.Lock(0, LockFlags.None);

    // On créé un tableau de vertices pour les mettre das le buffer :
    CustomVertex.PositionNormalTextured[] verts = (CustomVertex.PositionNormalTextured[])tmpArray;

    verts[0].X = -0.5f; verts[0].Y = 0.5f; verts[0].Z = 0.5f;//1-++
    verts[0].Tu = 0; verts[0].Tv = 0;
    verts[1].X = -0.5f; verts[1].Y = -0.5f; verts[1].Z = 0.5f;//0--+
    verts[1].Tu = 1; verts[1].Tv = 0;
    verts[2].X = 0.5f; verts[2].Y = 0.5f; verts[2].Z = 0.5f;//2+++
    verts[2].Tu = 0; verts[2].Tv = 1;

    verts[3].X = 0.5f; verts[3].Y = 0.5f; verts[3].Z = 0.5f;//2+++
    verts[3].Tu = 0; verts[3].Tv = 1;
    verts[4].X = -0.5f; verts[4].Y = -0.5f; verts[4].Z = 0.5f;//0--+
    verts[4].Tu = 1; verts[4].Tv = 0;
    verts[5].X = 0.5f; verts[5].Y = -0.5f; verts[5].Z = 0.5f;//3+-+
    verts[5].Tu = 1; verts[5].Tv = 1;

    //face2
    verts[6].X = -0.5f; verts[6].Y = -0.5f; verts[6].Z = 0.5f;//0--+
    verts[6].Tu = 1; verts[6].Tv = 1;
    verts[7].X = 0.5f; verts[7].Y = -0.5f; verts[7].Z = -0.5f;//4+--
    verts[7].Tu = 0; verts[7].Tv = 0;
    verts[8].X = 0.5f; verts[8].Y = -0.5f; verts[8].Z = 0.5f;//3+-+
    verts[8].Tu = 0; verts[8].Tv = 1;

    verts[9].X = -0.5f; verts[9].Y = -0.5f; verts[9].Z = 0.5f;//0--+
    verts[9].Tu = 1 ; verts[9].Tv = 1;
    verts[10].X = -0.5f; verts[10].Y = -0.5f; verts[10].Z = -0.5f;//7---
    verts[10].Tu = 1; verts[10].Tv = 0;
    verts[11].X = 0.5f; verts[11].Y = -0.5f; verts[11].Z = -0.5f;//4+--
    verts[11].Tu = 0; verts[11].Tv = 0;

    //ma face 3
    verts[12].X = -0.5f; verts[12].Y = -0.5f; verts[12].Z = 0.5f;//0--+
    verts[12].Tu = 0; verts[12].Tv = 0;
    verts[13].X = -0.5f; verts[13].Y = 0.5f; verts[13].Z = 0.5f;//1-++
    verts[13].Tu = 1; verts[13].Tv = 0;
    verts[14].X = -0.5f; verts[14].Y = 0.5f; verts[14].Z = -0.5f;//6-+-
    verts[14].Tu = 1; verts[14].Tv = 1;

    verts[15].X = -0.5f; verts[15].Y = -0.5f; verts[15].Z = 0.5f;//0--+
    verts[15].Tu = 0; verts[15].Tv = 0;
    verts[16].X = -0.5f; verts[16].Y = 0.5f; verts[16].Z = -0.5f;//6-+-
    verts[16].Tu = 1; verts[16].Tv = 1;
    verts[17].X = -0.5f; verts[17].Y = -0.5f; verts[17].Z = -0.5f;//7---
    verts[17].Tu = 0; verts[17].Tv = 1;
    //Face 4
    verts[18].X = -0.5f; verts[18].Y = 0.5f; verts[18].Z = 0.5f;//1-++
    verts[18].Tu = 1; verts[18].Tv = 1;
    verts[19].X = 0.5f; verts[19].Y = 0.5f; verts[19].Z = -0.5f;//5++-
    verts[19].Tu = 0; verts[19].Tv = 0;
    verts[20].X = -0.5f; verts[20].Y = 0.5f; verts[20].Z = -0.5f;//6-+-
    verts[20].Tu = 0; verts[20].Tv = 1;

    verts[21].X = 0.5f; verts[21].Y = 0.5f; verts[21].Z = 0.5f;//2+++
    verts[21].Tu = 1; verts[21].Tv = 0;
    verts[22].X = 0.5f; verts[22].Y = 0.5f; verts[22].Z = -0.5f;//5++-
    verts[22].Tu = 0; verts[22].Tv = 0;
    verts[23].X = -0.5f; verts[23].Y = 0.5f; verts[23].Z = 0.5f;////-++
    verts[23].Tu = 1; verts[23].Tv = 1;



    //f5
    verts[24].X = 0.5f; verts[24].Y = 0.5f; verts[24].Z = 0.5f;//2+++
    verts[24].Tu = 0; verts[24].Tv = 0;
    verts[25].X = 0.5f; verts[25].Y = -0.5f; verts[25].Z = 0.5f;//3+-+
    verts[25].Tu = 1; verts[25].Tv = 0;
    verts[26].X = 0.5f; verts[26].Y = -0.5f; verts[26].Z = -0.5f;//4+--
    verts[26].Tu = 1; verts[26].Tv = 1;

    verts[27].X = 0.5f; verts[27].Y = 0.5f; verts[27].Z = 0.5f;//2+++
    verts[27].Tu = 0; verts[27].Tv = 0;
    verts[28].X = 0.5f; verts[28].Y = -0.5f; verts[28].Z = -0.5f;//4+--
    verts[28].Tu = 1; verts[28].Tv =1;
    verts[29].X = 0.5f; verts[29].Y = 0.5f; verts[29].Z = -0.5f;//5++-
    verts[29].Tu = 0; verts[29].Tv = 1;

    //f6
    verts[30].X = 0.5f; verts[30].Y = -0.5f; verts[30].Z = -0.5f;//4+--
    verts[30].Tu = 1; verts[30].Tv = 1;
    verts[31].X = -0.5f; verts[31].Y = 0.5f; verts[31].Z = -0.5f;//6-+-
    verts[31].Tu = 0; verts[31].Tv = 0;
    verts[32].X = 0.5f; verts[32].Y = 0.5f; verts[32].Z = -0.5f;//5++-
    verts[32].Tu = 1; verts[32].Tv = 0;

    verts[33].X = 0.5f; verts[33].Y = -0.5f; verts[33].Z = -0.5f;//4+--
    verts[33].Tu = 1; verts[33].Tv = 1;
    verts[34].X = -0.5f; verts[34].Y = -0.5f; verts[34].Z = -0.5f;//7---
    verts[34].Tu = 0; verts[34].Tv = 1;
    verts[35].X = -0.5f; verts[35].Y = 0.5f; verts[35].Z = -0.5f;//6-+-
    verts[35].Tu = 0; verts[35].Tv = 0;

    this.vertexBuffer.Unlock(); // On libère le buffer de vertices.
    }
    catch (DriverInvalidCallException e) { MessageBox.Show("Erreur "+e.StackTrace); }
    // this.SetupMatrices();
    }

    // Called whenever the rendering device is reset
    void OnResetDevice(object sender, EventArgs e)
    {
    Device dev = (Device)sender;
    // Turn off culling, so we see the front and back of the triangle
    dev.RenderState.CullMode = Cull.None;
    // Turn off D3D lighting
    dev.RenderState.Lighting = false;
    // Turn on the ZBuffer
    dev.RenderState.ZBufferEnable = true;
    // Turn on perspective correction for textures
    // This provides a more accurate visual at the cost
    // of a small performance overhead
    dev.RenderState.TexturePerspective = true;
    // Now create our texture

    /* texture1 = TextureLoader.FromStream(dev,
    Assembly.GetExecutingAssembly().GetManifestResourceStream(
    "Texture.Content.pichy.bmp"));*/
    texture[0] = TextureLoader.FromStream(dev,
    Assembly.GetExecutingAssembly().GetManifestResourceStream(
    "Texture.Content.pichy.bmp"));
    texture[1] = TextureLoader.FromStream(dev,
    Assembly.GetExecutingAssembly().GetManifestResourceStream(
    "Texture.Content.Banana.bmp"));
    texture[2] = TextureLoader.FromStream(dev,
    Assembly.GetExecutingAssembly().GetManifestResourceStream(
    "Texture.Content.Banana.bmp"));
    texture[3] = TextureLoader.FromStream(dev,
    Assembly.GetExecutingAssembly().GetManifestResourceStream(
    "Texture.Content.Banana.bmp"));
    texture[4] = TextureLoader.FromStream(dev,
    Assembly.GetExecutingAssembly().GetManifestResourceStream(
    "Texture.Content.Banana.bmp"));
    texture[5] = TextureLoader.FromStream(dev,
    Assembly.GetExecutingAssembly().GetManifestResourceStream(
    "Texture.Content.Banana.bmp"));

    }


    // Sets up the world, view, and projection matrices each frame
    // Sets up the world, view, and projection matrices each frame
    private void SetupMatrices()
    {

    float angle = Environment.TickCount / 1000.0F;
    /*device.Transform.World =
    Matrix.RotationYawPitchRoll(angle, angle / 1.0F, 2);*/
    //device.Transform.World =
    //Matrix.RotationX(90);
    device.Transform.World =
    Matrix.RotationX(90);




    device.Transform.World = Matrix.RotationAxis(
    new Vector3(1.0f,
    1, 1.0f),
    Environment.TickCount / 1000.0f);


    // "up" to be in the y-direction.
    device.Transform.View = Matrix.LookAtLH(
    new Vector3(0.0f, 0.0f, -5.0f),
    new Vector3(0.0f, 0.0f, 0.0f),
    new Vector3(0.0f, 1.0f, 0.0f));


    device.Transform.Projection =
    Matrix.PerspectiveFovLH((float)Math.PI / 8.0f, 1.0f,
    1.0f, 100.0f);
    }

    protected void SetupMat()
    {
    float angle = Environment.TickCount / 800.0F;
    device.Transform.World =
    Matrix.RotationYawPitchRoll(angle, angle / 1.0F,1);
    device.Transform.View =
    Matrix.LookAtLH(new Vector3(0, 0.5F, -1000),
    new Vector3(0, 0.5F, 0), new Vector3(0, 1, 0));
    device.Transform.Projection =
    Matrix.PerspectiveFovLH((float)Math.PI / 1200.0F, 1.0F, 900.0F, 1100.0F);
    }


    // All rendering for each frame occurs here
    private void Render()
    {
    // On commence par tout vider et mettre du bleu en fond.
    this.device.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0);

    // Commencer à définir la scène
    this.device.BeginScene();
    //SetupMatrices();
    SetupMat();
    // Sélection de la source (numéro de la source, ou sont les vertices à afficher, 1er vertex à afficher)
    i = i % 6;
    device.SetTexture(0, texture[i]);
    device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;
    device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
    device.TextureState[0].AlphaOperation = TextureOperation.SelectArg1;
    device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor;
    device.TextureState[0].ResultArgument = TextureArgument.Current;
    i = i + 1;

    this.device.SetStreamSource(0, this.vertexBuffer, 0);

    // Enfin on indique le Vertexe de départ, ici 0, et le nombre de primitives a cré (= nombre de triangle), ici 1 puisque l'on a 3 vertexes.
    this.device.DrawPrimitives(PrimitiveType.TriangleList, 0, 12);

    this.device.EndScene(); // Fin de la définition
    this.device.Present(); // Lancer l'affichage
    }






    // Called when the window needs to be repainted
    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
    {
    // Render on painting
    j = j % 500;
    if (j==0)
    this.Render();
    j = j + 1;

    // Render again
    this.Invalidate();
    }

    // Called when the window background needs to be repainted
    protected override void OnPaintBackground(
    System.Windows.Forms.PaintEventArgs e)
    {
    // Don't paint the background
    }

    // Handles any keyboard keys which have been pressed
    protected override void OnKeyPress(
    System.Windows.Forms.KeyPressEventArgs e)
    {
    // Esc was pressed
    if ((int)(byte)e.KeyChar == (int)System.Windows.Forms.Keys.Escape)
    this.Close();
    }


    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main()
    {
    // Initialize Direct3D
    Cube f = new Cube();
    f.Show();
    Application.Run(f);

    }
    }
    }

  5. #5
    Membre actif Avatar de Luffy49
    Profil pro
    Étudiant
    Inscrit en
    Mars 2007
    Messages
    399
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Mars 2007
    Messages : 399
    Points : 247
    Points
    247
    Par défaut
    Tu aurais pu utiliser les balise [ code] du forum parcequ'on s'y retrouve pas trop la ...
    La connaissance n'est rien si elle n'est pas partagé

    Citation de Confucius :
    Ceux dont la connaissance est innée sont des hommes tout à fait supérieurs. Puis viennent ceux qui acquièrent cette connaissance par l'étude. Enfin, ceux qui, même dans la détresse, n'étudient pas : c'est le peuple.

  6. #6
    Nouveau Candidat au Club
    Inscrit en
    Mai 2007
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 5
    Points : 1
    Points
    1
    Par défaut balises et code C# sur mobile
    Citation Envoyé par Luffy49
    Tu aurais pu utiliser les balise [ code] du forum parcequ'on s'y retrouve pas trop la ...
    c'est quoi les balises?
    est-ce que tu as un autre code carément?
    Merci

  7. #7
    Nouveau Candidat au Club
    Inscrit en
    Mai 2007
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 5
    Points : 1
    Points
    1
    Par défaut
    Citation Envoyé par AbMILANO
    c'est quoi les balises?
    est-ce que tu as un autre code carément?
    Merci
    voici le fichier en attaché

    merci
    Fichiers attachés Fichiers attachés

  8. #8
    Nouveau Candidat au Club
    Inscrit en
    Mai 2007
    Messages
    5
    Détails du profil
    Informations forums :
    Inscription : Mai 2007
    Messages : 5
    Points : 1
    Points
    1
    Par défaut autre programme
    Bonjour,
    Voici un autre programme qui marche trés bien et que j'ai recuperé sur le net, le pb c'est qu'il ne veut pas tourner sur mon portable il marche que sur pc. comment je fais pôur qu'il fonctionne aussi sur portable

    cordialment
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. [XL-2010] Placer des images sur Word
    Par ZimCri dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 03/12/2012, 16h38
  2. Disparition des images sur les boutons
    Par troumad dans le forum GTK+ avec C & C++
    Réponses: 6
    Dernier message: 19/10/2012, 20h59
  3. [Matplotlib] Insérer des images sur les axes
    Par mOoler dans le forum Calcul scientifique
    Réponses: 0
    Dernier message: 13/06/2011, 10h20
  4. Placer des images sur une image avec un JFrame
    Par blackhock dans le forum Agents de placement/Fenêtres
    Réponses: 7
    Dernier message: 28/06/2009, 18h31
  5. [FAQ][VC++]Comment placer des images sur un menu contextuel
    Par Gabrielly dans le forum Contribuez
    Réponses: 0
    Dernier message: 14/04/2009, 18h48

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo