void MainWindow::BuildAntenna(){
	vp.clear();
	vn.clear();
	face.clear();
	face_cnt = 4000;
	BuildButtom();
	Sweepping();
	SetNormal();
	SetFace();
	std::ofstream mtlout("tmp.mtl");
	mtlout << "#tmp.mtl";
	mtlout.close();
	std::ofstream out("tmp.obj");
	out << "g default" << std::endl;
	for (int i = 0; i < vp.size(); i++)
	{
		out << "v " << vp[i].x << " " << vp[i].y << " " << vp[i].z << std::endl;
	}
	for (int i = 0; i < vn.size(); i++)
	{
		out << "vn " << vn[i].x << " " << vn[i].y << " " << vn[i].z << std::endl;
	}
	for (int i = 0; i < face.size(); i++)
	{
		out << "f " << face[i].idx1 << "//" << face[i].idx1 << " " << face[i].idx2 << "//" << face[i].idx2 << " " << face[i].idx3 << "//" << face[i].idx3 << std::endl;
	}
	out.close();
	antennaGLWidget->delAllGLList();
	Andu::AnduMeshReader reader;
	Caca::Mesh* pMesh = new Caca::Mesh();
	reader.Read(pMesh, "tmp.obj");
	antennaGLWidget->addGLList(1, pMesh);
	antennaGLWidget->updateGL();
}
Example #2
0
/* Pop_Arrow()
 *==========================================================================
 * Scroll the popup menu items if up or down arrow is selected.
 *
 * IN: int obj:		up or down arrow is selected.
 *     int *offset:	Offset into the menu items text array
 *     int num_items:   Total number of menu items involved.
 *     char *items[]:   Pointer to the text array
 *
 * OUT: void
 */
void
Pop_Arrow( int obj, int *offset, int num_items, char *items[] )
{
    OBJECT *tree;
    int draw = FALSE;
    int i;

    ActiveTree( ad_object );
    /* Up Arrow Selected AND not at the top */
    if( ( obj == Q1 ) && ( *offset > 0 ))
    {
        *offset -= 1;
        draw = TRUE;
    }

    /* DOWN Arrow and not within 3 items from the bottom */
    if( ( obj == Q5 ) && ( *offset < ( num_items - 3 ) ) )
    {
        *offset += 1;
        draw = TRUE;
    }

    if( draw )
    {
        for( i = ( Q2 - Q2 ); i <= Q4 - Q2; i++ )
        {
            TedText( i + Q2 ) = items[ *offset + i ];
            SetNormal( i + Q2 );
            Objc_draw( ad_object, i + Q2, 0, NULL );
        }
    }
}
Example #3
0
RAS_ITexVert::RAS_ITexVert(const MT_Vector3& xyz,
						 const MT_Vector4& tangent,
						 const MT_Vector3& normal)
{
	xyz.getValue(m_localxyz);
	SetNormal(normal);
	SetTangent(tangent);
}
Example #4
0
//--------------------------------------------------------------------------------------
// Create and blur a noise volume texture
//--------------------------------------------------------------------------------------
HRESULT SoftParticles::CreateNoiseVolume( ID3D11Device* pd3dDevice, UINT VolumeSize )
{
	HRESULT hr = S_OK;

	D3D11_SUBRESOURCE_DATA InitData;
	InitData.pSysMem = new CHAR4[ VolumeSize*VolumeSize*VolumeSize ];
	InitData.SysMemPitch = VolumeSize*sizeof(CHAR4);
	InitData.SysMemSlicePitch = VolumeSize*VolumeSize*sizeof(CHAR4);

	// Gen a bunch of random values
	CHAR4* pData = (CHAR4*)InitData.pSysMem;
	for( UINT i=0; i<VolumeSize*VolumeSize*VolumeSize; i++ )
	{
		pData[i].w = (char)(RPercent() * 128.0f);
	}

	// Generate normals from the density gradient
	float heightAdjust = 0.5f;
	D3DXVECTOR3 Normal;
	D3DXVECTOR3 DensityGradient;
	for( UINT z=0; z<VolumeSize; z++ )
	{
		for( UINT y=0; y<VolumeSize; y++ )
		{
			for( UINT x=0; x<VolumeSize; x++ )
			{
				DensityGradient.x = GetDensity( x+1, y, z, pData, VolumeSize ) - GetDensity( x-1, y, z, pData, VolumeSize )/heightAdjust;
				DensityGradient.y = GetDensity( x, y+1, z, pData, VolumeSize ) - GetDensity( x, y-1, z, pData, VolumeSize )/heightAdjust;
				DensityGradient.z = GetDensity( x, y, z+1, pData, VolumeSize ) - GetDensity( x, y, z-1, pData, VolumeSize )/heightAdjust;

				D3DXVec3Normalize( &Normal, &DensityGradient );
				SetNormal( Normal, x,y,z, pData, VolumeSize );
			}
		}
	}

	D3D11_TEXTURE3D_DESC desc;
	desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
	desc.CPUAccessFlags = 0;
	desc.Depth = desc.Height = desc.Width = VolumeSize;
	desc.Format = DXGI_FORMAT_R8G8B8A8_SNORM;
	desc.MipLevels = 1;
	desc.MiscFlags = 0;
	desc.Usage = D3D11_USAGE_IMMUTABLE;
	V_RETURN( pd3dDevice->CreateTexture3D( &desc, &InitData, &g_pNoiseVolume ) );

	D3D11_SHADER_RESOURCE_VIEW_DESC SRVDesc;
	ZeroMemory( &SRVDesc, sizeof(SRVDesc) );
	SRVDesc.Format = desc.Format;
	SRVDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
	SRVDesc.Texture3D.MipLevels = desc.MipLevels;
	SRVDesc.Texture3D.MostDetailedMip = 0;
	V_RETURN(pd3dDevice->CreateShaderResourceView( g_pNoiseVolume, &SRVDesc, &g_pNoiseVolumeRV ));
    
	delete InitData.pSysMem;
	return hr;
}
Example #5
0
void Wall2D::Read(ifstream &in)
{
    double x, y;
    in >> x >> y;
    SetFrom(CCPoint(x, y));
    in >> x >> y;
    SetTo(CCPoint(x,y));
    in >> x >> y;
    SetNormal(CCPoint(x, y));
}
Example #6
0
bool
vsMeshMakerTriangleVertex::AttemptMergeWith( vsMeshMakerTriangleVertex *other, const vsVector3D &faceNormalOther )
{
	const float epsilon = 0.01f;
	const float sqEpsilon = epsilon*epsilon;

	bool closeEnough = ((other->m_position - m_position).SqLength() < sqEpsilon);
	bool colorMatches = (other->m_color == m_color);
	bool texelMatches = ((other->m_texel - m_texel).SqLength() < sqEpsilon);

	//vsVector2D deltaTexel = other->m_texel - m_texel;
	//deltaTexel.x -= vsFloor(deltaTexel.x+0.5f);
	//deltaTexel.y -= vsFloor(deltaTexel.y+0.5f);

	if ( closeEnough && colorMatches ) //&& deltaTexel.SqLength() < sqEpsilon )
	{
		// check my normal against 'faceNormalOther'
		//vsAssert( m_flags & Flag_Normal, "error:  merging when I have no normal set??" );
		vsAssert( GetFirstTriangle(), "Merging a vertex which doesn't have any triangles??" );

		//if ( m_normal.Dot( faceNormalOther ) > s_mergeTolerance )
		vsVector3D faceNormal = GetFirstTriangle()->m_faceNormal;
		if ( faceNormal.Dot( faceNormalOther ) > s_mergeTolerance )
		{
			if ( m_mergeCount == 0 )
			{
				m_totalNormal = GetNormal();	// we keep track of the running total, so we can blend correctly.
			}

			m_mergeCount++;
			m_totalNormal += faceNormalOther;
			vsVector3D newNormal = m_totalNormal;
			newNormal.Normalise();
			SetNormal( newNormal );

			if ( !texelMatches )
			{
				other->SetNormal( newNormal );	// set the normal explicitly,
												// just to force the 'has normal'
												// flag on.

				// make the other vertex fake match me.
				other->m_fakeNormalMergedWith = this;
			}

			return texelMatches;
		}
	}

	vsAssert(false,"Tried to merge things taht can't merge??");
	return false;
}
Example #7
0
RAS_TexVert::RAS_TexVert(const MT_Point3& xyz,
						 const MT_Point2& uv,
						 const MT_Point2& uv2,
						 const MT_Vector4& tangent,
						 const unsigned int rgba,
						 const MT_Vector3& normal,
						 const bool flat,
						 const unsigned int origindex)
{
	xyz.getValue(m_localxyz);
	uv.getValue(m_uv1);
	uv2.getValue(m_uv2);
	SetRGBA(rgba);
	SetNormal(normal);
	tangent.getValue(m_tangent);
	m_flag = (flat)? FLAT: 0;
	m_origindex = origindex;
	m_unit = 2;
	m_softBodyIndex = -1;
}
Example #8
0
int
Set_Box( OBJECT *tree, int index, int cur_height,
         int Height, int Width, int Just, int FontSize,
         char *text )
{
    SetNormal( index );
    ObW( index )     = Width;
    TedJust( index ) = Just;
    TedFont( index ) = FontSize;
    TedText( index ) = text;
#if 0
    /* Do THIS ONLY if AES Version 0x0330 or Greater! */
    if(( AES_Version >= 0x0330 )
            && ( gl_ncolors > LWHITE ))
    {
        ObType( index ) |= 0x0100;/* DRAW3D */
        TedColor( index ) = ( TedColor( index ) & 0xFF70L ) | LWHITE | 0x70;
    }
#endif
    return( cur_height + Height );
}
Example #9
0
void
ConeAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("ConeAttributes");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("angle")) != 0)
        SetAngle(node->AsDouble());
    if((node = searchNode->GetNode("origin")) != 0)
        SetOrigin(node->AsDoubleArray());
    if((node = searchNode->GetNode("normal")) != 0)
        SetNormal(node->AsDoubleArray());
    if((node = searchNode->GetNode("representation")) != 0)
    {
        // Allow enums to be int or string in the config file
        if(node->GetNodeType() == INT_NODE)
        {
            int ival = node->AsInt();
            if(ival >= 0 && ival < 3)
                SetRepresentation(Representation(ival));
        }
        else if(node->GetNodeType() == STRING_NODE)
        {
            Representation value;
            if(Representation_FromString(node->AsString(), value))
                SetRepresentation(value);
        }
    }
    if((node = searchNode->GetNode("upAxis")) != 0)
        SetUpAxis(node->AsDoubleArray());
    if((node = searchNode->GetNode("cutByLength")) != 0)
        SetCutByLength(node->AsBool());
    if((node = searchNode->GetNode("length")) != 0)
        SetLength(node->AsDouble());
}
Example #10
0
RAS_TexVert::RAS_TexVert(const MT_Point3& xyz,
						 const MT_Point2 uvs[MAX_UNIT],
						 const MT_Vector4& tangent,
						 const unsigned int rgba,
						 const MT_Vector3& normal,
						 const bool flat,
						 const unsigned int origindex)
{
	xyz.getValue(m_localxyz);
	SetRGBA(rgba);
	SetNormal(normal);
	tangent.getValue(m_tangent);
	m_flag = (flat)? FLAT: 0;
	m_origindex = origindex;
	m_unit = 2;
	m_softBodyIndex = -1;

	for (int i = 0; i < MAX_UNIT; ++i)
	{
		uvs[i].getValue(m_uvs[i]);
	}
}
Example #11
0
void PolygonGroup::ApplyMatrix(const Matrix4 & matrix)
{
    aabbox = AABBox3(); // reset bbox
    
    Matrix4 normalMatrix4;
    matrix.GetInverse(normalMatrix4);
    normalMatrix4.Transpose();
    Matrix3 normalMatrix3;
    normalMatrix3 = normalMatrix4;

    for (int32 vi = 0; vi < vertexCount; ++vi)
    {
        Vector3 vertex;
        GetCoord(vi, vertex);
        vertex = vertex * matrix;
        SetCoord(vi, vertex);
        
        Vector3 normal;
        GetNormal(vi, normal);
        normal = normal * normalMatrix3;
        SetNormal(vi, normal);
    }    
}
Example #12
0
void
PlaneAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("PlaneAttributes");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("origin")) != 0)
        SetOrigin(node->AsDoubleArray());
    if((node = searchNode->GetNode("normal")) != 0)
        SetNormal(node->AsDoubleArray());
    if((node = searchNode->GetNode("upAxis")) != 0)
        SetUpAxis(node->AsDoubleArray());
    if((node = searchNode->GetNode("haveRadius")) != 0)
        SetHaveRadius(node->AsBool());
    if((node = searchNode->GetNode("radius")) != 0)
        SetRadius(node->AsDouble());
    if((node = searchNode->GetNode("threeSpace")) != 0)
        SetThreeSpace(node->AsBool());
}
Example #13
0
kexPlane::kexPlane(const kexVec3 &pt1, const kexVec3 &pt2, const kexVec3 &pt3) {
    SetNormal(pt1, pt2, pt3);
    this->d = kexVec3::Dot(pt1, Normal());
}
Example #14
0
void RAS_TexVert::Transform(const MT_Matrix4x4& mat, const MT_Matrix4x4& nmat)
{
	SetXYZ((mat*MT_Vector4(m_localxyz[0], m_localxyz[1], m_localxyz[2], 1.0)).getValue());
	SetNormal((nmat*MT_Vector4(m_normal[0], m_normal[1], m_normal[2], 1.0)).getValue());
	SetTangent((nmat*MT_Vector4(m_tangent[0], m_tangent[1], m_tangent[2], 1.0)).getValue());
}
Example #15
0
void CMDecodePage::SetHigh()
{
	SetNormal();
}
Example #16
0
void MODEL::DoDryRewet( PROJECT* project, int* dried, int* wetted )
{
  DRYREW *dryRew = &region->dryRew;

  region->Connection( 0L );

  int del = 0;
  int wel = 0;

  if( dryRew->method == 1 )
  {
    // mark nodes and elements to be rewetted ------------------------------------------------------
    wel = region->Rewet( dryRew->rewetLimit, dryRew->rewetPasses, project );

    // mark dry nodes and elements -----------------------------------------------------------------
    del = region->Dry( dryRew->dryLimit, dryRew->countDown );
  }
  else if( dryRew->method == 2 )
  {
    region->DryRewet( dryRew->dryLimit, dryRew->rewetLimit, dryRew->countDown, &del, &wel );
  }
  else if( dryRew->method == 3 )
  {
    region->RewetDry( dryRew->dryLimit, dryRew->rewetLimit, dryRew->countDown, &del, &wel );
  }
/*
  // future work ...
  else if( dryRew->method == 4 )
  {
    // determine dynamic boundary ------------------------------------------------------------------
    region.DynamicBound( np, node, *elem, dryRew->dryLimit, project );
  }
*/

  //////////////////////////////////////////////////////////////////////////////////////////////////

# ifdef _MPI_
  del = project->subdom.Mpi_sum( del );
  wel = project->subdom.Mpi_sum( wel );
# endif

  char text [200];

  sprintf( text, "\n (MODEL::DoDryRewet)     %d elements have got dry\n", del );
  REPORT::rpt.Output( text, 3 );

  sprintf( text, "\n (MODEL::DoDryRewet)     %d elements have got wet\n", wel );
  REPORT::rpt.Output( text, 3 );

  int dryRewFlag = del + wel;

  if( dryRewFlag )
  {
    ////////////////////////////////////////////////////////////////////////////////////////////////
    // exchange information on dry nodes on interfaces
#   ifdef _MPI_
    if( project->subdom.npr > 1 )
    {
      MPI_Comm_Dry( project, true );

      //////////////////////////////////////////////////////////////////////////////////////////////
      // reset wetted area, in case of dry nodes that are not dry in adjacent subdomains
      // added on 20.04.2006, sc

      if( dryRew->method == 2  ||  dryRew->method == 3 )
      {
        int wetted = 0;

        for( int n=0; n<region->Getnp(); n++ )
        {
          NODE* nd = region->Getnode(n);

          nd->mark = false;

          double H = nd->v.S - nd->zor;

          if( H < dryRew->dryLimit )
          {
            SF( nd->flag, NODE::kDry );
          }

          else if( isFS(nd->flag, NODE::kDry) )
          {
            nd->mark = true;

            CF( nd->flag, NODE::kDry );
            wetted++;
          }

          CF( nd->flag, NODE::kMarsh );
          nd->z = nd->zor;
        }


        if( dryRew->method == 2 )
        {
          region->DryRewet( dryRew->dryLimit, dryRew->rewetLimit, dryRew->countDown, &del, &wel );
        }
        else if( dryRew->method == 3 )
        {
          region->RewetDry( dryRew->dryLimit, dryRew->rewetLimit, dryRew->countDown, &del, &wel );
        }

        ////////////////////////////////////////////////////////////////////////////////////////////

        MPI_Comm_Dry( project, false );

        wetted = project->subdom.Mpi_sum( wetted );

        sprintf( text, "\n (MODEL::DoDryRewet)     %d interface nodes have got wet\n", wetted );
        REPORT::rpt.Output( text, 3 );
      }
    }


    ////////////////////////////////////////////////////////////////////////////////////////////////
    // reset interface flags: kInface, kInface_DN and kInface_UP; this is
    // necessary for the correct ordering of equations in EQS::ResetEqOrder()

    project->subdom.SetInface( region );

#   endif  //  #ifdef _MPI_
    ////////////////////////////////////////////////////////////////////////////////////////////////

    // determine 1D boundary elements and ----------------------------------------------------------
    // set up slip velocity boundary conditions

    Initialize();

    SetNormal();
    SetRotation();

    region->SetSlipFlow();

    REPORT::rpt.PrintTime( 3 );

//  ================================================================================================
#   ifdef kDebug_1
    for( int n=0; n<region->Getnp(); n++ )
    {
      NODE* ndbg = region->Getnode(n);

      switch( ndbg->Getname() )
      {
        case 3654:
          REPORT::rpt.Message( "\n" );
          REPORT::rpt.Message( "### NODE %6d: inface    = %d\n", ndbg->Getname(), ndbg->flag&NODE::kInface );
          REPORT::rpt.Message( "###            : inface_dn = %d\n", ndbg->flag&NODE::kInface_DN );
          REPORT::rpt.Message( "###            : inface_up = %d\n", ndbg->flag&NODE::kInface_UP );
          REPORT::rpt.Message( "\n" );
          REPORT::rpt.Message( "###            : dry       = %d\n", ndbg->flag&NODE::kDry );
          REPORT::rpt.Message( "###            : marsh     = %d\n", ndbg->flag&NODE::kMarsh );
          REPORT::rpt.Message( "###            : H         = %f\n", ndbg->v.S - ndbg->zor );
          REPORT::rpt.Message( "\n" );
          REPORT::rpt.Message( "###            : bound     = %d\n", ndbg->flag&NODE::kBound );
          REPORT::rpt.Message( "###            : inflow    = %d\n", ndbg->flag&NODE::kInlet );
          REPORT::rpt.Message( "###            : outflow   = %d\n", ndbg->flag&NODE::kOutlet );
          REPORT::rpt.Message( "###            : rotat     = %d\n", ndbg->flag&NODE::kRotat );
          REPORT::rpt.Message( "###            : noMoment  = %d\n", ndbg->flag&NODE::kNoMoment );
          REPORT::rpt.Message( "\n" );
          REPORT::rpt.Message( "###            : countDown = %d\n", ndbg->countDown );

          {
            SUB* sub = ndbg->sub;
            while( sub )
            {
              REPORT::rpt.Message( "### SUBDOM %4d: dry       = %d\n", sub->no+1, sub->dry );
              sub = sub->next;
            }
          }
          break;
      }
    }
#   endif
//  ================================================================================================
  }

  else
  {
    // set up structure for connection of nodes to elements ----------------------------------------
    // dry elements are not taken into consideration

    region->Connection( ELEM::kDry );
  }

  if( dried )  *dried  = del;
  if( wetted ) *wetted = wel;

  region->firstDryRew = false;
}
Example #17
0
void Flipper::RenderAtThickness(RenderDevice* pd3dDevice, float angle, float height,
                                float baseradius, float endradius, float flipperheight, Vertex3D_NoTex2* buf)
{
    Pin3D * const ppin3d = &g_pplayer->m_pin3d;

    Vertex2D vendcenter;
    Vertex2D rgv[4];
    SetVertices(0.0f, 0.0f, angle, &vendcenter, rgv, baseradius, endradius);

    Vertex3D_NoTex2 rgv3D[32];
    for (int l=0;l<8;l++)
    {
        rgv3D[l].x = rgv[l&3].x;
        rgv3D[l].y = rgv[l&3].y;
        rgv3D[l].z = (l<4) ? height + flipperheight + 0.1f : height; // Make flippers a bit taller so they draw above walls
        rgv3D[l].z *= m_ptable->m_BG_scalez[m_ptable->m_BG_current_set];
    }

    unsigned long offset = 0;

    SetNormal<Vertex3D_NoTex2,WORD>(rgv3D, rgi0123, 3, NULL, NULL, 4);
    // Draw top.
    buf[offset    ] = rgv3D[0];
    buf[offset + 1] = rgv3D[1];
    buf[offset + 2] = rgv3D[2];
    buf[offset + 3] = rgv3D[3];
    offset+=4;
    SetNormal<Vertex3D_NoTex2,WORD>(rgv3D, rgiFlipper1, 3, NULL, NULL, 4);
    // Draw front side wall.
    buf[offset    ] = rgv3D[0];
    buf[offset + 1] = rgv3D[4];
    buf[offset + 2] = rgv3D[5];
    buf[offset + 3] = rgv3D[1];
    offset+=4;
    SetNormal<Vertex3D_NoTex2,WORD>(rgv3D, rgiFlipper2, 3, NULL, NULL, 4);
    // Draw back side wall.
    buf[offset    ] = rgv3D[2];
    buf[offset + 1] = rgv3D[6];
    buf[offset + 2] = rgv3D[7];
    buf[offset + 3] = rgv3D[3];
    offset+=4;

    // offset = 12

    // Base circle
    for (int l=0;l<16;l++)
    {
        const float anglel = (float)(M_PI*2.0/16.0)*(float)l;
        rgv3D[l].x = /*m_d.m_Center.x*/ + sinf(anglel)*baseradius;
        rgv3D[l].y = /*m_d.m_Center.y*/ - cosf(anglel)*baseradius;
        rgv3D[l].z = height + flipperheight + 0.1f;
        rgv3D[l].z *= m_ptable->m_BG_scalez[m_ptable->m_BG_current_set];
        rgv3D[l+16].x = rgv3D[l].x;
        rgv3D[l+16].y = rgv3D[l].y;
        rgv3D[l+16].z = height;
        rgv3D[l+16].z *= m_ptable->m_BG_scalez[m_ptable->m_BG_current_set];
    }

    // Draw end caps of cylinders of large ends.
    WORD endCapsIndex[3*14];
    for (int l=0;l<14;l++)
    {
        endCapsIndex[l*3  ] = 0;
        endCapsIndex[l*3+1] = l+1;
        endCapsIndex[l*3+2] = l+2;
        SetNormal(rgv3D, endCapsIndex+l*3, 3);
    }
    memcpy( &buf[offset], rgv3D, sizeof(Vertex3D_NoTex2)*16 );
    offset += 16;

    // offset = 28

    // Draw vertical cylinders at large end of flipper.
    for (int l=0; l<16; l++)
    {
        // set normal according to cylinder surface
        const float anglel = (float)(M_PI*2.0/16.0)*(float)l;
        rgv3D[l].nx = rgv3D[l+16].nx = +sinf(anglel);
        rgv3D[l].ny = rgv3D[l+16].ny = -cosf(anglel);
        rgv3D[l].nz = rgv3D[l+16].nz = 0.0f;

        buf[offset] = rgv3D[l];
        buf[offset+1] = rgv3D[l+16];
        offset += 2;
    }

    // offset = 60

    // End circle.
    for (int l=0;l<16;l++)
    {
        const float anglel = (float)(M_PI*2.0/16.0)*(float)l;
        rgv3D[l].x = vendcenter.x + sinf(anglel)*endradius;
        rgv3D[l].y = vendcenter.y - cosf(anglel)*endradius;
        rgv3D[l].z = height + flipperheight + 0.1f;
        rgv3D[l].z *= m_ptable->m_BG_scalez[m_ptable->m_BG_current_set];
        rgv3D[l+16].x = rgv3D[l].x;
        rgv3D[l+16].y = rgv3D[l].y;
        rgv3D[l+16].z = height;
        rgv3D[l+16].z *= m_ptable->m_BG_scalez[m_ptable->m_BG_current_set];
    }

    // Draw end caps to vertical cylinder at small end.
    for (int l=0;l<14;l++)
        SetNormal(rgv3D, endCapsIndex+l*3, 3);

	memcpy( &buf[offset], rgv3D, sizeof(Vertex3D_NoTex2)*16 );
    offset += 16;

    // offset = 76

    // Draw vertical cylinders at small end.
    for (int l=0;l<16;l++)
    {
        const float anglel = (float)(M_PI*2.0/16.0)*(float)l;
        rgv3D[l].nx = rgv3D[l+16].nx = +sinf(anglel);
        rgv3D[l].ny = rgv3D[l+16].ny = -cosf(anglel);
        rgv3D[l].nz = rgv3D[l+16].nz = 0.0f;

        buf[offset] = rgv3D[l];
        buf[offset+1] = rgv3D[l+16];
        offset += 2;
    }

    // offset = 108
}
Example #18
0
stVertex3::stVertex3(const DexVector3& pos, const DexVector3& normal, float u, float v) :m_u(u), m_v(v)
{
    SetPos(pos);
    SetNormal(normal);
    SetColor(DEXCOLOR_WHITE);
}
void TerrainGenerator::RenderHeightMap()					// This Renders The Height Map As Quads
{
	glPushMatrix();
	int X = 0, Y = 0;									// Create Some Variables To Walk The Array With.
	int x, y, z;										// Create Some Variables For Readability
	glScalef(scaleValue, scaleValue * HEIGHT_RATIO, scaleValue);
	glTranslatef(-512,-120,-512);
	if(!g_HeightMap.size()) return;								// Make Sure Our Height Data Is Valid
	glCullFace(GL_BACK);
	glEnable(GL_CULL_FACE);

	fVector3d first;
	fVector3d second;
	fVector3d third;
	fVector3d a;
	fVector3d b;
	fVector3d n;
	double l;

	if(_vboInit) 
	{ 
		for ( X = 0; X < (MAP_SIZE-STEP_SIZE); X += STEP_SIZE )
		{
			for ( Y = 0; Y < (MAP_SIZE-STEP_SIZE); Y += STEP_SIZE )
			{
				//calcNormals
				first.x = X;
				first.y = Height(X, Y );
				first.z = Y;
				second.x = X;
				second.y = Height(X, Y + STEP_SIZE);
				second.z = Y + STEP_SIZE;
				third.x = X + STEP_SIZE;
				third.y = Height(X + STEP_SIZE, Y );
				third.z = Y;

				a.x = second.x - first.x;
				a.y = second.y - first.y;
				a.z = second.z - first.z;

				b.x = third.x - first.x;
				b.y = third.y - first.y;
				b.z = third.z - first.z;

				n.x = (a.y * b.z) - (a.z * b.y);
				n.y = (a.z * b.x) - (a.x * b.z);
				n.z = (a.x * b.y) - (a.y * b.x);

				// Normalize (divide by root of dot product)
				l = sqrt(n.x * n.x + n.y * n.y + n.z * n.z);
				n.x /= l;
				n.y /= l;
				n.z /= l;

				// Get The (X, Y, Z) Value For The Bottom Left Vertex
				x = X;							
				y = Height(X, Y );	
				z = Y;							

				SetTex(1.0f, 1.0f);
				SetNormal(n.x,n.y,n.z);
				SetVertice(x,y,z);
				
				// Get The (X, Y, Z) Value For The Top Left Vertex
				x = X;										
				y = Height(X, Y + STEP_SIZE );  
				z = Y + STEP_SIZE ;	

				SetTex(0.0f, 1.0f);
				SetNormal(n.x,n.y,n.z);
				SetVertice(x,y,z);							// Send This Vertex a VBO then To OpenGL To Be Rendered

				// Get The (X, Y, Z) Value For The Top Right Vertex
				x = X + STEP_SIZE; 
				y = Height(X + STEP_SIZE, Y + STEP_SIZE ); 
				z = Y + STEP_SIZE ;

				SetTex(0.0f, 0.0f);
				SetNormal(n.x,n.y,n.z);
				SetVertice(x,y,z);
				
				// Get The (X, Y, Z) Value For The Bottom Right Vertex
				x = X + STEP_SIZE; 
				y = Height(X + STEP_SIZE, Y ); 
				z = Y;

				SetTex(1.0f, 0.0f);
				SetNormal(n.x,n.y,n.z);
				SetVertice(x,y,z);
			}
		}
		InitVBO(); 
		_vboInit = false;
	}

	CreateVBO();							// Render Polygon
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glPopMatrix();
}
Example #20
0
void Bumper::RenderSetup(RenderDevice* pd3dDevice )
{
    if (m_d.m_state == LightStateBlinking)
        RestartBlinker(g_pplayer->m_time_msec);

   const float outerradius = m_d.m_radius + m_d.m_overhang;
   const float height = m_ptable->GetSurfaceHeight(m_d.m_szSurface, m_d.m_vCenter.x, m_d.m_vCenter.y) * m_ptable->m_zScale;

   Pin3D * const ppin3d = &g_pplayer->m_pin3d;
   Texture * const pin = m_ptable->GetImage(m_d.m_szImage);	

   float r = (float)(m_d.m_color & 255) * (float) (1.0/255.0);
   float g = (float)(m_d.m_color & 65280) * (float) (1.0/65280.0);
   float b = (float)(m_d.m_color & 16711680) * (float) (1.0/16711680.0);
   topNonLitMaterial.setAmbient( 1.0f, r*0.5f, g*0.5f, b*0.5f );
   topNonLitMaterial.setDiffuse( 1.0f, r*0.5f, g*0.5f, b*0.5f );
   topLitMaterial.setAmbient(1.0f, 0.0f, 0.0f, 0.0f );
   topLitMaterial.setDiffuse(1.0f, 0.0f, 0.0f, 0.0f );
   topLitMaterial.setEmissive( 0.0f, r, g, b );

   r = (float)(m_d.m_sidecolor & 255) * (float) (1.0/255.0);
   g = (float)(m_d.m_sidecolor & 65280) * (float) (1.0/65280.0);
   b = (float)(m_d.m_sidecolor & 16711680) * (float) (1.0/16711680.0);
   sideNonLitMaterial.setAmbient( 1.0f, r*0.5f, g*0.5f, b*0.5f );
   sideNonLitMaterial.setDiffuse( 1.0f, r*0.5f, g*0.5f, b*0.5f );
   sideLitMaterial.setAmbient(1.0f, 0.0f, 0.0f, 0.0f );
   sideLitMaterial.setDiffuse(1.0f, 0.0f, 0.0f, 0.0f );
   sideLitMaterial.setEmissive( 0.0f, r, g, b );

   nonLitMaterial.setAmbient( 1.0f, 0.5f, 0.5f, 0.5f );
   nonLitMaterial.setDiffuse( 1.0f, 0.5f, 0.5f, 0.5f );
   nonLitMaterial.setEmissive(0.0f, 0.0f, 0.0f, 0.0f );

   litMaterial.setAmbient( 1.0f, 0.0f, 0.0f, 0.0f );
   litMaterial.setDiffuse( 1.0f, 0.0f, 0.0f, 0.0f );
   litMaterial.setEmissive(0.0f, 1.0f, 1.0f, 1.0f );

   Vertex3D moverVertices[5*32];
   WORD     indices[4*32];
   WORD     normalIndices[6*32];

   std::vector<WORD> allIndices;        // collect all indices which should go into an index buffer
   allIndices.reserve(6*32 + 12*32);

   for (int l=0,i=0,t=0; l<32; l++,t+=6,i+=4)
   {
      normalIndices[t  ] = (l==0) ? 31 : (l-1);
      normalIndices[t+1] = (l==0) ? 63 : (l+31);
      normalIndices[t+2] = (l==0) ? 33 : (l+1);
      normalIndices[t+3] = l;
      normalIndices[t+4] = l+32;
      normalIndices[t+5] = (l<30) ? (l+2) : (l-30);

      indices[i  ] = l;
      indices[i+1] = 32 + l;
      indices[i+2] = 32 + (l+1) % 32;
      indices[i+3] = (l+1) % 32;

      allIndices.push_back(l);
      allIndices.push_back(32 + l);
      allIndices.push_back(32 + (l+1) % 32);
      allIndices.push_back(l);
      allIndices.push_back(32 + (l+1) % 32);
      allIndices.push_back((l+1) % 32);

      const float angle = (float)(M_PI*2.0/32.0)*(float)l;
      const float sinangle =  sinf(angle);
      const float cosangle = -cosf(angle);

      // top circle of base cylinder
      moverVertices[l].x = sinangle*m_d.m_radius + m_d.m_vCenter.x;
      moverVertices[l].y = cosangle*m_d.m_radius + m_d.m_vCenter.y;
      moverVertices[l].z = height+(40.0f+m_d.m_heightoffset)*m_ptable->m_zScale;
      moverVertices[l].nx = sinangle;
      moverVertices[l].ny = cosangle;
      moverVertices[l].nz = 0.0f;

      // bottom circle of base cylinder
      moverVertices[l+32] = moverVertices[l];
      moverVertices[l+32].z = height;

      // top circle of cap
      moverVertices[l+64].x = sinangle*outerradius*0.5f + m_d.m_vCenter.x;
      moverVertices[l+64].y = cosangle*outerradius*0.5f + m_d.m_vCenter.y;
      moverVertices[l+64].z = height+(60.0f+m_d.m_heightoffset)*m_ptable->m_zScale;

      // middle ring of cap
      moverVertices[l+96].x = sinangle*outerradius*0.9f + m_d.m_vCenter.x;
      moverVertices[l+96].y = cosangle*outerradius*0.9f + m_d.m_vCenter.y;
      moverVertices[l+96].z = height+(50.0f+m_d.m_heightoffset)*m_ptable->m_zScale;

      // outer rim of cap
      moverVertices[l+128].x = sinangle*outerradius + m_d.m_vCenter.x;
      moverVertices[l+128].y = cosangle*outerradius + m_d.m_vCenter.y;
      moverVertices[l+128].z = height+(40.0f+m_d.m_heightoffset)*m_ptable->m_zScale;

      moverVertices[l].tu = 0.5f+sinangle*0.5f;
      moverVertices[l].tv = 0.5f-cosangle*0.5f;
      moverVertices[l+32].tu = 0.5f+sinangle*0.5f;
      moverVertices[l+32].tv = 0.5f-cosangle*0.5f;
      moverVertices[l+64].tu = 0.5f+sinangle*0.25f;
      moverVertices[l+64].tv = 0.5f-cosangle*0.25f;
      moverVertices[l+96].tu = 0.5f+sinangle*(float)(0.5*0.9);
      moverVertices[l+96].tv = 0.5f-cosangle*(float)(0.5*0.9);
      moverVertices[l+128].tu = 0.5f+sinangle*0.5f;
      moverVertices[l+128].tv = 0.5f-cosangle*0.5f;

      if ( pin )
      {
         moverVertices[l+64].tu = 0.5f+sinangle*0.25f;
         moverVertices[l+64].tv = 0.5f+cosangle*0.25f;
         moverVertices[l+96].tu = 0.5f+sinangle*(float)(0.5*0.9);
         moverVertices[l+96].tv = 0.5f+cosangle*(float)(0.5*0.9);
         moverVertices[l+128].tu = 0.5f+sinangle*0.5f;
         moverVertices[l+128].tv = 0.5f+cosangle*0.5f;

         const float lightmaxtu = 0.8f;
         const float lightmaxtv = 0.8f;

         moverVertices[l].tu2 = moverVertices[l].tu;
         moverVertices[l+32].tu2 = moverVertices[l+32].tu;
         moverVertices[l].tv2 = moverVertices[l].tv;
         moverVertices[l+32].tv2 = moverVertices[l+32].tv;
         moverVertices[l+64].tu2 = (0.5f+sinangle*0.25f)*lightmaxtu;
         moverVertices[l+64].tv2 = (0.5f+cosangle*0.25f)*lightmaxtv;
         moverVertices[l+96].tu2 = (0.5f+sinangle*(float)(0.5*0.9))*lightmaxtu;
         moverVertices[l+96].tv2 = (0.5f+cosangle*(float)(0.5*0.9))*lightmaxtv;
         moverVertices[l+128].tu2 = (0.5f+sinangle*0.5f)*lightmaxtu;
         moverVertices[l+128].tv2 = (0.5f+cosangle*0.5f)*lightmaxtv;
      }
   }
   ppin3d->CalcShadowCoordinates(moverVertices,32*5);

   for( int l=0,k=0; l<32*12; l+=6,k+=4 )
   {
      allIndices.push_back( k   );
      allIndices.push_back( k+1 );
      allIndices.push_back( k+2 );
      allIndices.push_back( k   );
      allIndices.push_back( k+2 );
      allIndices.push_back( k+3 );
   }


   if (idxBuf)
       idxBuf->release();
   idxBuf = pd3dDevice->CreateAndFillIndexBuffer( allIndices );

   Vertex3D dynVerts[8*32];
   for (int l=0,t=0,k=0,ofs=0; l<32; l++,t+=6,k+=4,ofs+=8)
   {
      SetNormal(&moverVertices[64], &normalIndices[t], 3, NULL, &indices[k], 2);
      SetNormal(&moverVertices[96], &normalIndices[t], 3, NULL, &indices[k], 2);
      SetNormal(&moverVertices[64], &normalIndices[t+3], 3, NULL, &indices[k+2], 2);
      SetNormal(&moverVertices[96], &normalIndices[t+3], 3, NULL, &indices[k+2], 2);
      dynVerts[ofs  ] = moverVertices[64+indices[k  ]];
      dynVerts[ofs+1] = moverVertices[64+indices[k+1]];
      dynVerts[ofs+2] = moverVertices[64+indices[k+2]];
      dynVerts[ofs+3] = moverVertices[64+indices[k+3]];
      dynVerts[ofs+4] = moverVertices[96+indices[k  ]];
      dynVerts[ofs+5] = moverVertices[96+indices[k+1]];
      dynVerts[ofs+6] = moverVertices[96+indices[k+2]];
      dynVerts[ofs+7] = moverVertices[96+indices[k+3]];
   }

   static const WORD rgiBumperStatic[32] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
   SetNormal(&moverVertices[64], rgiBumperStatic, 32, NULL, NULL, 0);

   if (!vtxBuf)
       pd3dDevice->CreateVertexBuffer(32+8*32+2*32, 0, MY_D3DFVF_VERTEX, &vtxBuf);

   Vertex3D *buf;
   vtxBuf->lock(0, 0, (void**)&buf, 0);
   memcpy(buf, &moverVertices[64], 32*sizeof(buf[0]));
   memcpy(buf+32, dynVerts, 8*32*sizeof(buf[0]));
   memcpy(buf+32+8*32, moverVertices, 2*32*sizeof(buf[0]));
   vtxBuf->unlock();

   // ensure we are not disabled at game start
   m_fDisabled = fFalse;
}