Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Anddos

Member Since 01 Nov 2002
Offline Last Active Today, 04:58 PM

Topics I've Started

first person camera rotations to 2d sprite rotation

Today, 06:21 AM

 if i have a first person camera and a 2d radar, howdo i use the camera rotations for the sprite 2d rotations for the placement of the player on the radar

 

i think what i first need todo is

 

D3DXVec3TransformCoord on either the view matrix or the inverse of the view matrix, after that i am unsure how do turn them in to 2d rotations in screenspace

 

thanks if you can help


how to create gui buttons with DirectX 11?

27 November 2014 - 03:56 PM

I know how to make gui buttons with DirectX 9 with rhw etc, how would you do it for DirectX 11?

 

Picture of what i mean

 

http://i.imgur.com/Fik6fhU.png?1


view frustum culling particle effects?

17 November 2014 - 09:09 PM

I am wondering can you use view frustrum culling on particle effects such as fire,smoke etc, i am rendering them using point_list but cant figure out how to not render the effects when the camera is not viewing them


Cant get this third person camera coding working

13 November 2014 - 11:48 AM

i want a third person camera where i can rotate in a sphere type motion around the 3d triangle, ive found this code and moddified it abit to where i think it should work but its not, there is no movement with the camera whats so ever

//camera.h

#ifndef CAMERA_H
#define CAMERA_H

//#include "vector.h"
#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>

 // Default amount for the eye to be away from the camera's target
const D3DXVECTOR3 kWorldUp(0,1,0); // Direction of up (+Y axis) in world space

const float kMoveAmt = 10.0f * (1.0f / 60.0f);
    
// The camera
class CCamera
{
    public:
        
        CCamera();
        
        void rotateY(float angle, const D3DXVECTOR3 &target); // Rotates around world Y-axis
        void pitch(float angle, const D3DXVECTOR3 &target); // Rotates around the camera's X-axis
                        
        void setEye(const D3DXVECTOR3 &eyePos) { eye = eyePos; } // Sets the eye position of the camera
        void setTarget(const D3DXVECTOR3 &target); // Sets the camera to look at "target"
        
        // Returns what the camera's target is
        D3DXVECTOR3 getTarget() const { return eye + (forward * kCamDist); }
        
        // Data Access ***
        
            D3DXVECTOR3 getEye() const { return eye; }
            D3DXVECTOR3 getCamForward() const { return forward; } // Returns camera's forward vector
            D3DXVECTOR3 getCamUp() const { return up; } // Returns camera's up vector
            D3DXVECTOR3 getCamRight() const { return right; } // Returns camera's right vector
        
        // *** End Data Access
        
    private:
    
    
        D3DXVECTOR3 right; // The local normalized axis that points to the "right"
        D3DXVECTOR3 up; // The local normalized axis that points "up"
        D3DXVECTOR3 forward; // The local normalized axis that points "forward"
        
        D3DXVECTOR3 eye; // Where we are looking from
        float kCamDist;
};



#endif

//camera.cpp

#include "stdafx.h"
#include "camera.h"
#include <assert.h>

// Default Constructor
CCamera::CCamera()
{
    kCamDist = 2.5f;
    right = D3DXVECTOR3(1.0f, 0.0f, 0.0f); // +X axis
    up = D3DXVECTOR3(0.0f, 1.0f, 0.0f); // +Y axis
    forward = D3DXVECTOR3(0.0f, 0.0f, 1.0f); // +Z axis

    // Set eye back kCamDist units on the -Z axis
    eye = D3DXVECTOR3(0.0f, 0.0f, -kCamDist);
    
}

// Rotates camera's eye around the world Y-axis
// Using your standard Y-axis rotation matrix, we'll rotate around the Y-axis
// ca == cosf(angle)    sa == sinf(angle)
// [ ca 0 -sa ]
// [ 0  1   0 ]
// [ sa 0  ca ]
void CCamera::rotateY(float angle, const D3DXVECTOR3 &target)
{
    float xxx, zzz;
    float sinAng, cosAng;
    
    // Get sin()/cos() of angle
    sinAng = sinf(angle);
    cosAng = cosf(angle);
    
    // First translate to the world's origin
    eye -= target;
    
    // Save off forward components for computation
    xxx = eye.x;
    zzz = eye.z;
    
    // Rotate forward vector
    eye.x = xxx * cosAng + zzz * sinAng;
    eye.z = xxx * -sinAng + zzz * cosAng;
    
    // Translate back
    eye += target;
    
    setTarget(target); // Build the camera's axes
}

void CCamera::pitch(float angle, const D3DXVECTOR3 &target)
{
    // Compute the sin and cos of the angle
    float sinAng = sinf(angle);
    float cosAng = cosf(angle);
    
    eye -= target; // Translate to world's origin

    // Calculate new eye X component
    float xxx = (right.x * right.x * (1.0f - cosAng) + cosAng) * eye.x +
                (right.x * right.y * (1.0f - cosAng) + right.z * sinAng) * eye.y +
                (right.x * right.z * (1.0f - cosAng) - right.y * sinAng) * eye.z;

    // Calculate new Y component       
    float yyy = (right.x * right.y * (1.0f - cosAng) - right.z * sinAng) * eye.x +
                (right.y * right.y * (1.0f - cosAng) + cosAng) * eye.y +
                (right.y * right.z * (1.0f - cosAng) + right.x * sinAng) * eye.z;

    // Calculate new Z component
    float zzz = (right.x * right.z * (1.0f - cosAng) + right.y * sinAng) * eye.x +
                (right.y * right.z * (1.0f - cosAng) - right.x * sinAng) * eye.y +
                (right.z * right.z * (1.0f - cosAng) + cosAng) * eye.z;

    eye = D3DXVECTOR3(xxx, yyy, zzz); // Set the eye
    eye += target; // Translate back
    
    // Get vector from target to eye
    D3DXVECTOR3 vec = eye - target;
    D3DXVec3Normalize(&vec,&vec);
    //vec.normalize();
    
    // Position eye so that's always "kCamDist" from target
    eye = target + (vec * kCamDist);
    
    setTarget(target); // Build the camera's axes
}
    
// Builds the camera's axes by using the eye, target, and world's up vector
void CCamera::setTarget(const D3DXVECTOR3 &target)
{
    // Compute new forward vector (line of sight vector)
    forward = target - eye;
    D3DXVec3Normalize(&forward,&forward);
    
    // Compute new right vector
    //right = kWorldUp.cross(forward);
    D3DXVec3Cross(&right,&up,&forward);
    D3DXVec3Normalize(&right,&right);
    
    // Compute new camera up vector
    //up = forward.cross(right);
    D3DXVec3Cross(&up,&right,&forward);
    D3DXVec3Normalize(&up,&up);
}

//main.cpp

CCamera CCameraObj;

void CameraMouseInput(void);

void CameraMouseInput()
{
    const float kMaxAngle = 80.0f;
    static float pitchAmt = 0.0f; // Amout we've looked up or down
    const float kMoveAmt = 10.0f * (1.0f / 60.0f);
    

    // Get the middle of the screen
    int midScrX = GetSystemMetrics(SM_CXSCREEN) >> 1;
    int midScrY = GetSystemMetrics(SM_CYSCREEN) >> 1;

    float amt;
    POINT pt = {0};

    GetCursorPos(&pt); // Get the current mouse position

    // Rotate left/right
    amt = float(pt.x - midScrX) * kMoveAmt;
    CCameraObj.rotateY(DEG2RAD(amt), D3DXVECTOR3(0.0f,0.0f,0.0f));

    // Rotate up/down
    amt = float(midScrY - pt.y) * kMoveAmt;
    
    // Cap pitch
    if(pitchAmt + amt < -kMaxAngle)
    {
        amt = -kMaxAngle - pitchAmt;
        pitchAmt = -kMaxAngle;
    }
    else if(pitchAmt + amt > kMaxAngle)
    {
        amt = kMaxAngle - pitchAmt;
        pitchAmt = kMaxAngle;
    }
    else
    {
        pitchAmt += amt;
    }
    
    // Pitch the camera up/down
    CCameraObj.pitch(DEG2RAD(amt), D3DXVECTOR3(0.0f,0.0f,0.0f));

    SetCursorPos(midScrX, midScrY); // Set our cursor back to the middle of the screen
}

//render loop

 while(TRUE)
    {
        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        if(msg.message == WM_QUIT)
            break;
        
        CameraMouseInput();

        render_frame();
    }

inside draw

void render_frame(void)
{
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

    // Sets up the view of the scene based on passed in eye and target
    setViewMatrix(CCameraObj);

    d3ddev->BeginScene();
   //rest of drawing code not needed here

void setViewMatrix(const CCamera camera)
{
    D3DXMATRIXA16 matrix;
    D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); // World's up vector


    D3DXMatrixLookAtLH(&matrix, (D3DXVECTOR3*)(&camera.getEye()),
                       (D3DXVECTOR3*)(&camera.getTarget()), &up);
    d3ddev->SetTransform(D3DTS_VIEW, &matrix); // Set our view of the world
}

parsing .obj and loading in directx 9

07 November 2014 - 11:31 AM

so i have parsed all the data in the obj file and stored them in vectors

 

std::vector<DWORD> indices;
std::vector<D3DXVECTOR3> vertPos;
std::vector<D3DXVECTOR3> vertNorm;
std::vector<D3DXVECTOR2> vertTexCoord;

 

I am abit stuck creating the VertexBuffer from the vector and also the indexbuffer using these functions

 

d3ddev->CreateIndexBuffer()
d3ddev->CreateVertexBuffer()

 

i know most of what the params are, i just dont know how to store the actual data in to them from vectors

 

for loading your own custom cube for example you do

   // create an index buffer interface called i_buffer
    d3ddev->CreateIndexBuffer(36*sizeof(short),
                              0,
                              D3DFMT_INDEX16,
                              D3DPOOL_MANAGED,
                              &i_buffer,
                              NULL);

    // lock i_buffer and load the indices into it
    i_buffer->Lock(0, 0, (void**)&pVoid, 0);
    memcpy(pVoid, indices, sizeof(indices));
    i_buffer->Unlock();
 // create a vertex buffer interface called v_buffer
    d3ddev->CreateVertexBuffer(24*sizeof(CUSTOMVERTEX),
                               0,
                               CUSTOMFVF,
                               D3DPOOL_MANAGED,
                               &v_buffer,
                               NULL);

    VOID* pVoid;    // a void pointer

    // lock v_buffer and load the vertices into it
    v_buffer->Lock(0, 0, (void**)&pVoid, 0);
    memcpy(pVoid, vertices, sizeof(vertices));
    v_buffer->Unlock();

my attempt would be

 

thanks if you can help


PARTNERS