Results 1 to 10 of 10

Thread: DirectX DrawPrimitive real image scale

  1. #1

    DirectX DrawPrimitive real image scale

    Hello

    how can I set the real scale of a image for my sprite?
    using a single value for scale i can change the width and height of it, but i want the "real scale".

    i'm using drawPrimitive to draw it.

    my code is here:

    http://www.lordzero.co.nr/tmp/RealScale.zip

    Greets
    Knowledge is power.

  2. #2

    DirectX DrawPrimitive real image scale

    I see you transforming the vertices (scaling them) before the are put into the vertexbuffer.
    This is not the most efficient way of dealing with transformations.
    Matrices are a lot more efficient. Take a look at this:

    http://msdn2.microsoft.com/en-us/library/bb206269.aspx

    Matrices describe linear transformations (translations, rotations, scale and some other things).
    I think you need to study them first... they are not as easy as XY coords.

    You can set world, view and projection matrices. In this case, you probably want to set the world matrix. You can set the world matrix as follows:

    [pascal]
    D3DDevice.SetTransform( D3DTS_WORLD, MyWorldMatrix )
    [/pascal]

    This is probably what you want:

    [pascal]
    //Scale is a single, the scale factor
    //Scalemat is a TD3Dmatrix

    D3DXmatrixScaling( ScaleMat, Scale, Scale , 1);

    D2DDevice.SetTransform( D3DTS_WORLD, Scalemat );
    [/pascal]

    If you want to use multiple transformations (like Scaling and Translation) you need to multiply the matrices with D3DXMatrixMultiply.

    I dont know what you mean with 'real scale', but i think you want to pass the width and height to the render function instead of the scale factor. If so, you need to retrieve the texture size (Check IDirect3dTexture9.GetSurfaceDesc ). You can draw your sprite as a 1x1 rectangle and let a matrix scale, translate and rotate it as you wish.

    Hope this helps.
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  3. #3

    DirectX DrawPrimitive real image scale

    Quote Originally Posted by chronozphere
    I see you transforming the vertices (scaling them) before the are put into the vertexbuffer.
    This is not the most efficient way of dealing with transformations.
    Matrices are a lot more efficient. Take a look at this:

    http://msdn2.microsoft.com/en-us/library/bb206269.aspx

    Matrices describe linear transformations (translations, rotations, scale and some other things).
    I think you need to study them first... they are not as easy as XY coords.

    You can set world, view and projection matrices. In this case, you probably want to set the world matrix. You can set the world matrix as follows:

    [pascal]
    D3DDevice.SetTransform( D3DTS_WORLD, MyWorldMatrix )
    [/pascal]

    This is probably what you want:

    [pascal]
    //Scale is a single, the scale factor
    //Scalemat is a TD3Dmatrix

    D3DXmatrixScaling( ScaleMat, Scale, Scale , 1);

    D2DDevice.SetTransform( D3DTS_WORLD, Scalemat );
    [/pascal]

    If you want to use multiple transformations (like Scaling and Translation) you need to multiply the matrices with D3DXMatrixMultiply.

    Hope this helps.
    i believe that your code only work with orthogonal camera, because i'm using a vertex with D3DFVF_XYZRHW. with this i think that D3DX transformations dont will work...
    Knowledge is power.

  4. #4

    DirectX DrawPrimitive real image scale

    somebody have suggestions?
    Knowledge is power.

  5. #5
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    DirectX DrawPrimitive real image scale

    Just a question off-topic, but I see much often that previous posts are quoted. Why quote when you just answer? No offense, but please don't.

    On-topic: D3DFVF_XYZRHW are screenspace coordinates. If you just try to scale a quad, I think you need to calculate the vertex buffer for yourself. You could consider rendering full 3D. This is done in one of my projects: Uber Zombie. This way it's also very easy to scroll/rotate the camera without recalculating everything.

    Uber Zombie: http://necrodome.homeftp.net/Project..._Uber%20Zombie
    NecroSOFT - End of line -

  6. #6

    DirectX DrawPrimitive real image scale

    its already solved... thanks for the attention
    Knowledge is power.

  7. #7
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    DirectX DrawPrimitive real image scale

    what you do to solve?
    NecroSOFT - End of line -

  8. #8

    DirectX DrawPrimitive real image scale

    Quote Originally Posted by NecroDOME
    what you do to solve?
    Nathan from your country give me this source:

    Code:
    procedure TMainForm.FormCreate(Sender: TObject);
    const X = 0;
          Y = 0;
          Width = 100;
          height = 100; //X, Y and width and height of your sprite in pixels
    var R: TRect;
        _X,_Y,_Width,_Height: single; //X,Y,Width,Height passed to D3D
    begin
    
      if initd3d<>d3d_ok then showmessage&#40;'Error'&#41;;
    
      DXBase.Direct3DDevice.SetRenderState&#40;D3DRS_CULLMODE, D3DCULL_NONE&#41;;
      DXBase.Direct3DDevice.SetRenderState&#40;D3DRS_LIGHTING, iFalse&#41;;
    
      Windows.GetClientRect&#40;MainForm.Handle,R&#41;;
      
      if FAILED&#40;D3DXCreateTextureFromFile&#40;
        DXBase.Direct3DDevice,
        'image.jpg',
        pTexture&#41;
      &#41; then
      begin
        MessageBox&#40;0, 'failed', 'error', MB_OK&#41;;
        Exit;
      end;
    
      _X &#58;= &#40;X-&#40;R.Right/2&#41;&#41;; 
      _Y &#58;= -&#40;Y-&#40;R.Bottom/2&#41;&#41;; 
    
      //Crop coordinates into a 2x2 space &#40;the total D3D window&#41; 
      _X &#58;= &#40;_X * &#40;2/R.Right&#41;&#41;; 
      _Y &#58;= &#40;_Y * &#40;2/R.Bottom&#41;&#41;; 
    
      //calculate width and height 
      _width &#58;= Width * &#40;2/R.Right&#41;; 
      _height &#58;= -height * &#40;2/R.Bottom&#41;;  //flip Y axis 
    
      Vertices&#91;0&#93;.X &#58;= _X; 
      Vertices&#91;0&#93;.Y &#58;= _Y; 
      Vertices&#91;0&#93;.Z &#58;= 0; 
      Vertices&#91;0&#93;.Color &#58;= $FFFFFFFF; 
      Vertices&#91;0&#93;.tU &#58;= 0; 
      Vertices&#91;0&#93;.tV &#58;= 0; 
    
      Vertices&#91;1&#93;.X &#58;= _X + _Width; 
      Vertices&#91;1&#93;.Y &#58;= _Y; 
      Vertices&#91;1&#93;.Z &#58;= 0; 
      Vertices&#91;1&#93;.Color &#58;= $FFFFFFFF; 
      Vertices&#91;1&#93;.tU &#58;= 1; 
      Vertices&#91;1&#93;.tV &#58;= 0; 
    
      Vertices&#91;2&#93;.X &#58;= _X; 
      Vertices&#91;2&#93;.Y &#58;= _Y + _Height; 
      Vertices&#91;2&#93;.Z &#58;= 0; 
      Vertices&#91;2&#93;.Color &#58;= $FFFFFFFF; 
      Vertices&#91;2&#93;.tU &#58;= 0; 
      Vertices&#91;2&#93;.tV &#58;= 1; 
    
      Vertices&#91;3&#93;.X &#58;= _X + _Width; 
      Vertices&#91;3&#93;.Y &#58;= _Y + _Height; 
      Vertices&#91;3&#93;.Z &#58;= 0; 
      Vertices&#91;3&#93;.Color &#58;= $FFFFFFFF; 
      Vertices&#91;3&#93;.tU &#58;= 1; 
      Vertices&#91;3&#93;.tV &#58;= 1; 
    
      if FAILED&#40;
        DXBase.Direct3DDevice.CreateVertexBuffer&#40;
          4 * SizeOf&#40;TCustomVertex&#41;,
          0, D3DFVF_CUSTOMVERTEX,
          D3DPOOL_DEFAULT, pVB, nil&#41;&#41; then
        Exit;
    
      if FAILED&#40;
        pVB.Lock&#40;0, SizeOf&#40;Vertices&#41;, pVertices, 0&#41;&#41; then
      Exit;
    
      CopyMemory&#40;pVertices, @Vertices, SizeOf&#40;Vertices&#41;&#41;;
      pVB.Unlock;
    Knowledge is power.

  9. #9
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    DirectX DrawPrimitive real image scale

    So your rendering "full 3D" , no more XYZRHW?
    NecroSOFT - End of line -

  10. #10

    DirectX DrawPrimitive real image scale

    Quote Originally Posted by NecroDOME
    So your rendering "full 3D" , no more XYZRHW?
    i'm using XYZRHW
    Knowledge is power.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •